【发布时间】:2023-04-06 06:04:01
【问题描述】:
首先,我的 bean 由 spring 管理,而不是由 JSF 管理,我正在使用 this article 中描述的自定义视图范围。因此,如果常规 JSF2 的行为很奇怪并且可能与 Spring 有关,请告诉我。
豆子:
public class DepartmentBean {
private DefaultTreeModel model;
public void preRender(ComponentSystemEvent event) throws Exception {
if (model == null) {
model = myService.buildModel();
}
}
public String clear() {
// resetting stuff
return "pretty:";
}
}
查看:
<h:form>
<ice:panelGroup styleClass="crud-links">
<h:commandLink value="Delete" action="#{department.deleteDepartment}" />
</ice:panelGroup>
</h:form>
<h:form>
<ice:panelGroup>
<ice:tree id="tree" value="#{department.model}" var="item" hideRootNode="false" hideNavigation="false" imageDir="./xmlhttp/css/xp/css-images/">
<ice:treeNode>
<f:facet name="content">
<ice:panelGroup style="display: inline">
<ice:commandLink value="#{item.userObject.text}"></ice:commandLink>
</ice:panelGroup>
</f:facet>
</ice:treeNode>
</ice:tree>
</ice:panelGroup>
</h:form>
第一次加载页面时,model 对象填充了数据,但是当单击删除按钮时,我注意到在清除 preRender() 方法后执行并且模型(在清除之前填充为空,并获取再次填充,虽然我在同一页面,它应该保持值)
代码是否存在导致此类行为的问题,或者这是正常行为? 如果问题可能与 Spring 或自定义视图范围或 IceFaces 有关,请告知。
更新- 要求:
我想在页面构建时初始化树模型,当我仍在页面上时,树模型不会再次初始化,直到我以编程方式执行此操作。
【问题讨论】:
-
功能需求并不完全清楚,但听起来好像是要在 bean 的(后)构建期间构建模型,而不是在每次渲染视图之前。
-
问题已更新,希望现在清楚。