与p:对话框相比,PrimeFaces对话框将会分割视图范围吗? [英] Will PrimeFaces Dialog Framework break view scope as compared to p:dialog?

查看:192
本文介绍了与p:对话框相比,PrimeFaces对话框将会分割视图范围吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PrimeFaces 5。



当按下按钮时,我想打开一个对话框。

 < p:commandButton value =add uploadactionListener =#{theForm.openUpload}> 

  public void openUpload(){
this.item = new Item();
RequestContext.getCurrentInstance()。openDialog(uploadForm);
}

对话框中将有一个保存按钮来保存输入。

 < h:commandButton value =#{text ['button.add']}id =addstyleClass =btn btn-defaultactionListener =#{theForm.confirmAdd}/> 

  public void confirmAdd(){
RequestContext.getCurrentInstance()。closeDialog(uploadForm);
}

我的托管bean是 @ViewScoped 。如果对话框位于由PrimeFaces Dialog Framework完成的外部文件中,命令按钮是否会中断视图范围?每当我点击添加上传按钮,就会再次调用 @PostConstruct 方法,就像范围丢失一样。



< 官方博客的p>评论部分说,它不会破坏视图范围,但< a href =http://forum.primefaces.org/viewtopic.php?f=3&t=38235 =nofollow>这里的论坛是核心开发人员说 openDialog ()创建一个新视图,因此它会中断视图范围。



有人可以确认吗?


< PrimeFaces对话框框架基本上显示了一个< iframe> 标签中的另一个视图,div class =h2_lin>解决方案

我不会打断视图范围,但对话框视图将具有自己的范围,因为它实际上是一个不同的页面。这在不同的情况下可能是也可能不是可取的。正如PrimeFaces的用户指南所说:


对话框(DF)用于在
对话框中打开外部xhtml页面,在运行时动态生成。





  • p:dialog


    • 存在相同的视图范围。

    • 可以轻松地拥有相同的会话环境。

    • 静态定义,对话框和它的组件在构建视图中立即创建。你只能延迟渲染,例如使用 dynamic = true

    • 声明式定义意味着它更易于阅读和维护,因为对话框的存在并没有在java代码中隐藏。


  • 对话框。


    • 具有自己的视图范围。

    • 开发人员必须担心传递参数,传播会话上下文。 (和PF不支持 includeViewParams ,直到5.1。)

    • 动态创建意味着对话框,它的组件将不会被创建,直到对话框实际打开,但每次打开一个新的对话框将被创建。如果对话框打开多次,总体性能将会更大,加上许多对话框视图可能会耗尽JSF视图限制并过期其他视图。

    • 强制性动态创建可以提高资源效率某些情况例如。根据用户输入显示几十个特定的对话框。或者一个很少使用的对话框,可以从任何应用程序页面打开。




我的建议是默认使用p:dialog。仅在最后一个项目符号中提到的情况下才使用Dialog Framework。


I'm using PrimeFaces 5.

I would like to open a dialog when a button is pressed.

<p:commandButton value="add upload" actionListener="#{theForm.openUpload}" >

public void openUpload() {
    this.item = new Item();
    RequestContext.getCurrentInstance().openDialog("uploadForm");
}

There will be a save button in the dialog to save the inputs.

<h:commandButton value="#{text['button.add']}" id="add" styleClass="btn btn-default" actionListener="#{theForm.confirmAdd}"/>

public void confirmAdd() {
    RequestContext.getCurrentInstance().closeDialog("uploadForm");
}

My managed bean is @ViewScoped. Will the command button break the view scope if the dialog is in an external file as done by PrimeFaces Dialog Framework? Whenever I click the "add upload" button, the @PostConstruct method is called again just like the scope is lost.

Comments section of the official blog says it won't break the view scope, but here the forum a core developer says openDialog() creates a new view, therefore it breaks the view scope.

Can someone confirm this?

解决方案

PrimeFaces' Dialog Framework basically shows another view in an <iframe> tag. I wouldn't call that breaking a view scope, but the dialog view will have it's own scope, because it is practically a different page. That may or may not be desirable in different circumstances. As PrimeFaces' User Guide says:

Dialog Framework (DF) is used to open an external xhtml page in a dialog that is generated dynamically on runtime.

  • p:dialog
    • Exists in the same view scope.
    • Can easily have the same conversation context.
    • Statically defined, the dialog and its components get created immediately on build view. You can only delay rendering, e.g. with a dynamic=true.
    • Declarative definition means it's more readable and maintainable, because the dialog's existence is not hidden somewhere in java code.
  • Dialog Framework.
    • Has its own view scope.
    • Developer has to worry about passing parameters, propagating conversation context. (And PF didn't support includeViewParams until 5.1.)
    • Dynamic creation means dialog and its components won't be created until the dialog is actually opened, but a new dialog will be created each time it's opened. If the dialog is opened many times, the total performance hit will be larger, plus many dialog views can exhaust JSF view limit and expire other views.
    • Imperative dynamic creation allows for more resource efficiency in certain cases. E.g. show one specific dialog out of dozens based on user input. Or a rarely used dialog, which could be opened from any page of an application.

My recommendation would be to use p:dialog by default. Only use Dialog Framework in cases like I mentioned in the last bullet point.

这篇关于与p:对话框相比,PrimeFaces对话框将会分割视图范围吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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