Primefaces ajax根据backbean结果更新不同的面板
发布时间:2020-12-16 02:46:06 所属栏目:百科 来源:网络整理
导读:我是JSF,Primefaces和Ajax的新手,所以我要做的是更新一个面板,如果我的后端bean的验证是真的,并且当它是假的时更新另一个面板. h:panelGroup id="panel1" ... h:commandButton id="btn1" action="#{bean.validate}" p:ajax process="panel1" update="panel1"
我是JSF,Primefaces和Ajax的新手,所以我要做的是更新一个面板,如果我的后端bean的验证是真的,并且当它是假的时更新另一个面板.
<h:panelGroup id="panel1"> ... <h:commandButton id="btn1" action="#{bean.validate}"> <p:ajax process="panel1" update="panel1"/> </h:commandButton> </h:panelGroup> <h:panelGroup id="panel2"> ... </h:panelGroup> 后豆: public void validate() { ... if(validatecondition) { // Update panel 1 } else { // update panel 2 } } 那么使用ajax可以做到这一点吗?提前致谢!! 解决方法
当然,有两种方式.既然你正在使用primefaces,那么两种选择就更容易了
>使用RequestContext对象有选择地更新面板.您的代码将如下所示: public void validate() { RequestContext context = RequestContext.getCurrentInstance(); if(validatecondition) { context.update("panel1"); } else { context.update("panel2"); } } > JSF FacesContext ctxt = FacesContext.getCurrentInstance(); //get your hands on the current request context if(validatecondition) { ctxt.getPartialViewContext().getRenderIds().add("panel1"); } else { ctxt.getPartialViewContext().getRenderIds().add("panel2"); } getRenderIds()调用返回一个组件ID列表,JSF将在响应完成时通过ajax更新.这基本上是primefaces中的RequestContext将在幕后进行的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |