Send an f:param when a ValueChangeListener is invoked

user321068 picture user321068 · Nov 22, 2011 · Viewed 8.8k times · Source

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>

Answer

BalusC picture BalusC · Nov 22, 2011

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"));
    // ...
}