jnt30
jnt30

Reputation: 1367

JSF2: Is there any way to use a4j:param with rich:select or h:selectOneMenu

Is it possible to use with dropdown menus or is it also dependent on the parent object implementing ActionSource as the f:setPropertyActionLister is?

Ideally I would have done something like the following:

<h:selectOneMenu value="#{myCustomBean.selectedItemIndex}">
    <f:selectItems value="#{adminLetterAdminBean.missingSettings}" var="n" itemValue="#{n.id}" itemLabel="#{n.name}"/>
    <f:setPropertyActionListener value="42" target="#{adminLetterAdminBean.someProperty}" />
    <a4j:ajax />
</rich:select>

However this does not work because h:selectOneMenu does not implement javax.faces.component.ActionSource. The page does not render and it gives me a friendly stack trace to tell me about this dependency.

Not seeing anything in the Richfaces documentation about this constraint, I tried the following:

<h:selectOneMenu value="#{myCustomBean.selectedItemIndex}">
    <f:selectItems value="#{adminLetterAdminBean.missingSettings}" var="n" itemValue="#{n.id}" itemLabel="#{n.name}"/>
    <a4j:param assignTo="#{adminLetterAdminBean.someProperty}" value="42" name="randomRequestParamName"/>
    <a4j:ajax />
</rich:select>

This does not blow up, but it also does not set the property. I was wondering if there is a set a (or multiple) properties in a similar fashion.

Upvotes: 2

Views: 2695

Answers (2)

Nirdesh Sharma
Nirdesh Sharma

Reputation: 732

I had a similiar problem. My page has to transfer information about the autocomplete before the autocomplete request is done. I achieved this by using jsFunction. My autocomplete looks like:

<rich:autocomplete mode="ajax" showButton="true" value="#{conf.fieldValue}" 
      autocompleteMethod="#{BackingBean.search.autocomplete}" 
      minChars="3" onfocus="sendInfo('#{conf.label}')">
</rich:autocomplete>

Depending on conf.label (conf is a forEach variable) different data is fetched by the backing bean in the autocomplete method.

The transfer of this information is done by jsFunction (just after the autocomplete declaration):

<a4j:jsFunction name="sendInfo">
     <a4j:param name="param1" assignTo="#{BackingBean.search.currentAutocomplete}"/>
</a4j:jsFunction>

Just, when the user puts the focus on a specific autocomplete "sendInfo" is executed with one parameter which is bound to the backing bean.

Upvotes: 0

Max Katz
Max Katz

Reputation: 1582

a4j:param can only be nested inside an action component such as a4j:commandButon, a4j:commandLink and a4j:jsFunction. You can also use it with the standard button/link components.

Upvotes: 1

Related Questions