p:在侦听器之前调用ajax getter进行更新

Rav*_*avi 7 jsf primefaces

这是我的复选框.我正在侦听器中准备逗号分隔的组件ID字符串.这里的问题是在调用侦听器之前调用getter getUpdateComponentList().所以字符串永远不会更新.

<p:outputPanel>
<h:selectManyCheckbox value="#{form.colors}">
  <f:selectItems value="#{form.colorItems}"/>
  <p:ajax listener="#{form.testListener}" event="change" update="#{form.updateComponentList}"  />
</h:selectManyCheckbox>
</p:outputPanel>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 10

这是预期的行为.PrimeFaces(和标准JSF)不重新评估update(和render,oncomplete等)的属性以每个请求基础.它们是基于每个视图进行评估的.例如,RichFaces在其中完成<a4j:ajax>并完全产生预期的行为.

对于PrimeFaces,最好的办法是删除update属性并使用RequestContext#addPartialUpdateTarget()#addPartialUpdateTargets()在操作方法中.

例如

RequestContext.getCurrentInstance().addPartialUpdateTargets(updateComponentList);
Run Code Online (Sandbox Code Playgroud)

它需要Collection<String>诸如List<String>Set<String>.

顺便说一下,这event="change"是不必要的.只需使用组件的默认事件.


更新为较新版本PrimeFaces谁是后来读这个答案并不能找到它们在较新的版本PrimeFaces确实删除了上述方法的用户; 使用两种update()方法中的一种(一种采用a String,另一种采用a Collection<String>).

RequestContext.getCurrentInstance().update(updateComponentList);
Run Code Online (Sandbox Code Playgroud)