【发布时间】:2017-03-28 18:16:24
【问题描述】:
我正在尝试创建一个动态面板(带有各种项目的面板)然后我想将它与视图页面中的面板组件绑定,具有面板对象的托管 bean 的范围是@ViewScoped。
我注意到任何ajax 在视图页面中渲染此面板都会重建托管 bean,这是为什么呢?
这是我的代码:
这是托管 bean:
package test;
import org.icefaces.ace.component.panel.Panel;
@ManagedBean(name = "myBean")
@ViewScoped
public class myBean {
private Panel myPanel;
// Constructor
public myBean() {
myPanel = drawPanel(); // this function initiate and add items to the panel
}
// Setters and Getters Methods
}
这是查看页面:
<h:form>
<ace:panel binding="#{myBean.myPanel}"></ace:panel>
<ace:pushButton actionListener="#{myBean.something}">
<ace:ajax render="@form" />
</ace:pushButton>
</h:form>
在我每次按下按钮时,都会调用托管 bean 构造函数,为什么会发生这种情况? 我还注意到,如果我从面板组件中删除绑定属性或创建托管 bean 会话或应用程序范围的范围,则不会调用构造函数。
注意:我使用的是 icefaces 3 和 jsf 2.0。
这种情况有什么解决办法吗?
【问题讨论】:
标签: jsf managed-bean icefaces