问题
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