Search code examples
jsfparametersjsf-1.2valuechangelistener

Send an f:param when a ValueChangeListener is invoked


I want to send a request parameter, everytime a ValueChangeListener is invoked. I've implemented it the following way, but unfortunately it doesn't work.

Here's the code so you can get the idea.

<h:selectOneMenu value="#{MyBean.code}" 
   valueChangeListener="#{MyBean.codeChanged}" onchange="this.form.submit()">
   <f:selectItems value="#{MyBean.codeItems}" />
   <f:param name="validation" value="true" />
</h:selectOneMenu>

Solution

  • The <f:param> is not supported in this construct. For JSF 1.2, it's supported in <h:commandLink>, <h:outputLink> and <h:outputFormat> only. Your best bet is a <f:attribute>.

    <h:selectOneMenu value="#{MyBean.code}" 
        valueChangeListener="#{MyBean.codeChanged}" onchange="this.form.submit()">
        <f:selectItems value="#{MyBean.codeItems}" />
        <f:attribute name="validation" value="true" />
    </h:selectOneMenu>
    

    with

    public void codeChanged(ValueChangeEvent event) {
        UIInput menu = (UIInput) event.getComponent();
        boolean validation = Boolean.valueOf(component.getAttributes().get("validation"));
        // ...
    }