rich:pickList with Ajax updates
I have a RichFaces pick开发者_JS百科List 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?
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.).
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>
<h:form>
<rich:pickList value="#{pickListBean.result}">
<f:selectItems value="#{capitalsBean.capitalsOptions}"/>
<a4j:support event="onlistchanged" reRender="result"/>
</rich:pickList>
</h:form>
精彩评论