How to get component value from ActionEvent object?

拈花ヽ惹草 提交于 2019-12-24 14:26:19

问题


i am using ajax4jsf with jsf 1.1 and i have code like:

<h:selectOneMenu id="INPUT_PO_DocCategory" binding="#{PrinceOfficeBean.PO_DocCategory}" style="width:200px;">
          <f:selectItem itemLabel="test" itemValue="123"/>
          <f:selectItem itemLabel="test2" itemValue="456"/>
         <a4j:support event="onchange" actionListener="#{PrinceOfficeBean.processDocumentCategoryValueChange}" reRender="INPUT_PO_DocType" />
</h:selectOneMenu> 

this code is static and i can get selectOne value through PO_DocCategory binded object the question is: is it possible to get the component value in actionlistener through the action event object ?

public void processDocumentCategoryValueChange(ActionEvent e) throws Exception {
   // get component value from ActionEvent 
 }

回答1:


Classic way in JSF is to use value attribute of input component, e.g.:

<h:selectOneMenu value="#{bean.value}">
    ...
</h:selectOneMenu>

The input value will be stored in value attribute of the bean, and can be used by action listener to operate on.

It is still possible to get the value in action listener in 'alternative' way:

((EditableValueHolder) event.getComponent().getParent()).getValue() 


来源:https://stackoverflow.com/questions/20309576/how-to-get-component-value-from-actionevent-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!