How to get component value from ActionEvent object?

Mahmoud Saleh picture Mahmoud Saleh · Dec 1, 2013 · Viewed 8.5k times · Source

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 
 }

Answer

Andrey picture Andrey · Dec 1, 2013

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()