Primefaces p:ajax listener conditional update

时光怂恿深爱的人放手 提交于 2020-01-06 14:04:23

问题


JSF Page:

<p:commandButton>
  <p:ajax process="@this" update="name desc msg"
    listener="#{bean.deleteListener}"/>
</p:commandButton>

Bean:

public void deleteListener() {
  if (data.size() == 0) {
    // updates only "msg"
    setMsg("There is no data to delete");
    return;
  }
  setMsg("Data deleted.");
  // and updates the bean values for "name" and "desc" also.
  ...
}

Is it possible to conditionally update for an ajax call based on ajax listener logic. I would like to update the client ids "name desc msg" conditionally as shown in the listener code below (note this is a sample scenario in a larger application). The application uses Primefaces 5. Thanks.


回答1:


Sure, use the PrimeFaces RequestContext in your listener

RequestContext context = RequestContext.getCurrentInstance();

//update panel
context.update("form:panel");

See also: - http://www.primefaces.org/showcase/ui/misc/requestContext.xhtml



来源:https://stackoverflow.com/questions/29093119/primefaces-pajax-listener-conditional-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!