2

I have a RichFaces pickList from which the user should be able to select multiple items and it should be directly reflected on the backing bean. Right now I have no way to reload selection in case of a validation error or in case the page is reloaded. Is there a simple way to tell RichFaces that I want the backing list to be updated on every change?

cdecker
  • 4,515
  • 8
  • 46
  • 75

3 Answers3

2

You can attach to onlistchange event.

Using a4j:support:

<rich:pickList ...>
    <a4j:support event="onlistchange"/>
</rich:pickList>

Or, in newer versions, using a4j:ajax:

<rich:pickList ...>
    <a4j:ajax event="change" render="result"/>
</rich:pickList>

Or using a4j:jsFunction:

<rich:pickList onlistchange="listChange();"... />
<a4j:jsFunction name="listChange" />

Both approaches in the form above will submit the form causing submitting selected values. You can also specify additional attributes for a4j:support/a4j:jsFunction if needed (for example ajaxSingle="true" for a4j:support to process only pickList component (other inputs will not be validated/updated), action/actionListener to execute server side logic when list is changed, reRender, etc.).

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Andrey
  • 6,526
  • 3
  • 39
  • 58
  • My mistake, it was the missing tag around the picklist which let the ajax update die. But your answer is closest, congrats :D – cdecker Sep 20 '11 at 21:37
1

Have you try to declare your pickList in a panel with ajaxRendered="true" ? This should automatically reRender the pickList

<a4j:outputPanel ajaxRendered="true">
  <rich:pickList...
</a4j:outputPanel>
Jean-Charles
  • 1,690
  • 17
  • 28
-2

<h:form> <rich:pickList value="#{pickListBean.result}"> <f:selectItems value="#{capitalsBean.capitalsOptions}"/> <a4j:support event="onlistchanged" reRender="result"/> </rich:pickList> </h:form>