开发者

How to pass selected value as parameter for passing in a4j:support

I have one <h:selectOneMenu> inside that <a4j:support> is written. I have to pass the currently selected value through <a4j:support> as a parame开发者_如何学Cter to action. How can I do this?

<rich:modalPanel>

 <a4j:form>
 <rich:dataTable value="#{factoryCollectionOfUsers}" var="foo">
 <h:selectOneMenu name="role">
                        <s:selectItems
                           value="#{userAction.roleArray}"
                           var="role" label="#{role}"
                           noSelectionLabel="Please select" />
                        <a4j:support event="onchange" ajaxSingle="true"
                           action="#{userAction.setSelection}">
                        </a4j:support>
                        <s:convertEnum />

              </h:selectOneMenu>
  </rich:dataTable>
</a4j:form>
</rich:modalPanel>


You can pass the parameters from JSF page to the backing beans 's action method using the Method expression (For JSF 2.0) ,or <f:param> ,or <f:attribute> , or f:setPropertyActionListener .

You can refer to http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ for reference.


Try something like this:

<h:form> 
  <h:selectOneMenu value="#{foo.theChosenValue}"
    required="true" valueChangeListener="#{foo.processValueChange}"
    onchange="this.form.submit();">
        <s:selectItems
                       value="#{userAction.roleArray}"
                       var="role" label="#{role}"
                       noSelectionLabel="Please select" />
     <s:convertEnum />
  </h:selectOneMenu>
</h:form>

Your component should then:

@Name("foo")
public class Foo {
    @Getter @Setter Enum theChosenValue; //I don't know your type

    public void processValueChange(ValueChangeEvent value) throws AbortProcessingException {
        if (value != null) {
            if (value.getNewValue() instanceof Enum) {
                this.theChosenValue = (Enum) value.getNewValue();
            }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜