如何从ActionEvent对象获取组件值? [英] How to get component value from ActionEvent object?
问题描述
我在jsf 1.1中使用ajax4jsf,并且我的代码如下:
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>
此代码是静态的,我可以通过PO_DocCategory
绑定对象获取selectOne值
问题是:是否可以通过动作事件对象在actionlistener中获取组件值?
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
}
推荐答案
JSF中的经典方法是使用输入组件的value属性,例如:
Classic way in JSF is to use value attribute of input component, e.g.:
<h:selectOneMenu value="#{bean.value}">
...
</h:selectOneMenu>
输入值将存储在bean
的value
属性中,并且可以由动作侦听器用来对其进行操作.
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()
这篇关于如何从ActionEvent对象获取组件值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!