根据backbean结果Primefaces AJAX更新不同的面板 [英] Primefaces ajax update different panels according to backbean result

查看:135
本文介绍了根据backbean结果Primefaces AJAX更新不同的面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的JSF,Primefaces和Ajax,所以我想要做的就是更新一个面板,如果在我的背上豆验证为真,并更新另一个面板时,它是假的。

I'm new to JSF, Primefaces and Ajax, so what i'm trying to do is update one panel if a validation on my back bean is true and update another panel when it's false.

<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?在此先感谢!

So is it possible to do this using ajax? Thanks in advance!!

推荐答案

当然,两种方式。由于您使用primefaces,两个选项更容易将

Sure, two ways. Since you're using primefaces, the easier of two options would be

  1. 使用的RequestContext 反对选择性地更新面板。您的code将是这样的:

  1. Use the RequestContext object to update the panels selectively. Your code will look like this:

 public void validate() {
   RequestContext context = RequestContext.getCurrentInstance();
   if(validatecondition) {
     context.update("panel1");
   } else {
     context.update("panel2");
   }
}

  • JSF <一href="http://docs.oracle.com/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/api/javax/faces/context/PartialViewContext.html"><$c$c>PartialViewContext可以做同样的工作,有一点点打字

  • JSF PartialViewContext can do the same job, with just a little more typing

    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更新响应完成的列表。这基本上是的RequestContext 在primefaces将引擎盖下做的。

    The getRenderIds() call returns a list of component Ids that JSF will update via ajax on completion of the response. This is basically what RequestContext in primefaces will do under the hood.

    这篇关于根据backbean结果Primefaces AJAX更新不同的面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆