JSF @ ViewScope,PrimeFaces< p:对话框和< ui:include [英] JSF @ViewScope, PrimeFaces <p:dialog and <ui:include

查看:184
本文介绍了JSF @ ViewScope,PrimeFaces< p:对话框和< ui:include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主页和对话框上有:按钮.

I have: button on main page and dialog.

A希望对执行该对话框的托管bean(NewDialog.java)拥有ViewScope生命周期. 换句话说:在按下按钮时重新创建NewDialog bean,并在关闭对话框时销毁.

A would like to have ViewScope life cycle for managed bean (NewDialog.java), what perform the dialog. In other words: recreate the NewDialog bean while pushing the button, and destroy while closing dialog.

但是NewDialog bean在加载主页时已创建. 如何强制仅在按下按钮时创建的bean?

But NewDialog bean has created while loading main page. How to force bean created only when you press a button?

<ui:composition
   <h:form id="mainForm">
      <p:commandButton value="New Dialog"
                  onclick="newDialogVar.show();"/>  
   </h:form>

        <ui:include src="#{viewScopedBean.page}.xhtml" />
    </ui:define>
</ui:composition>

包含的页面:

    <ui:composition ..
        <f:view >
       <h:form id="formId"
         <p:dialog appendToBody="false"
                  dynamic="true"
                  modal="true"
                  widgetVar="newDialogVar">

              <p:commandButton value="Ok"
                         actionListener="#{newDialog.ok}"/>
      </h:form>
    </p:dialog>
    </f:view>
</ui:composition>

Bean:

@ManagedBean
@ViewScoped
public class NewDialog implements Serializable{

  @PostConstruct
    protected void postConstruct() {
        LOG.info("----------------- PostConstruct -------------------");
    }
}

我使用:PrimeFaces 3.5和Mojarra 2.1.22

I use: PrimeFaces 3.5 with Mojarra 2.1.22

提前谢谢!

P.S. :根据研究,我添加了:

P.S. : according research I add:

<context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
</context-param>

到web.xml.

推荐答案

这是预期的行为. <ui:include>在视图构建期间运行,而不是在视图渲染期间运行.因此,即使您有条件地渲染其父级之一,它仍将在构建/还原视图期间评估其src属性.可以在此答案中找到有关视图构建时间"与视图渲染时间"的深入背景说明:

This is expected behavior. The <ui:include> runs during view build time, not during view render time. So even if you conditionally render one of its parents, it will still evaluate its src attribute during building/restoring of the view. In depth background explanation of "view build time" versus "view render time" can be found in this answer: JSTL in JSF2 Facelets... makes sense?

您的具体功能要求尚不清楚,因此我无法详细说明正确的方法,但是事实是,如果您想推迟bean的创建以显示对话框,则需要寻找另一种方法.也许您需要将bean分成两个,一个保存包含路径,另一个保存对话框的数据?

Your concrete functional requirement is unclear, so I can't elaborate the right approach in detail, but fact is, you need to look for an alternate approach if you want to postpone the creation of the bean to display of the dialog. Perhaps you need to split the bean in two ones, one holding the include path and another holding the dialog's data?

这篇关于JSF @ ViewScope,PrimeFaces&lt; p:对话框和&lt; ui:include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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