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

11.2k Views Asked by At

I have one <h:selectOneMenu> inside that <a4j:support> is written. I have to pass the currently selected value through <a4j:support> as a parameter 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>
2

There are 2 best solutions below

0
On

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.

0
On

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