执行操作后查看范围将字段重置为默认值

发布于 2024-12-17 11:02:51 字数 1785 浏览 2 评论 0原文

首先,我的 bean 由 spring 管理,而不是由 JSF 管理,并且我使用自定义视图范围,如 本文。因此,如果该行为对于常规 JSF2 来说很奇怪并且可能与 Spring 有关,请告诉我。

Bean:

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 有关,请告知。

更新-要求

我想在构建页面时初始化树模型,当我仍在页面上时,树模型不会再次初始化,直到我以编程方式执行此操作。

First of all, my beans are managed by spring not by JSF and I am using custom view scope as described in this article. So if the behavior is weird for regular JSF2 and might be related to Spring, please tell me.

Bean:

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:";
    }

}

View:

<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>

When page is loaded for first time the model object is populated with data, but when clicking delete button I notice that after clearing preRender() method is executed and the model (which was populated before clearing becomes null, and gets populated again, although I am in same page, and it should maintain the value)

Does the code have a problem that leads to such behavior, or this is the normal behavior?
If the problem maybe related to Spring or the custom view scope or the IceFaces, please advise.

UPDATE- REQUIREMENT:

I want to initialize the tree model on construction of the page, and while i am still on the page the tree model doesn't gets initialized again until i do that programatically .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨离汐 2024-12-24 11:02:51

哦,我的错误,初始化应该在@PostConstruct 内部。

oh my mistake, initialization should be inside @PostConstruct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文