View scope reset fields to default after performing an action

admin

Administrator
Staff member
First of all, my beans are managed by spring not by JSF and I am using custom view scope as described in <a href="http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/" rel="nofollow">this article</a>. So if the behavior is weird for regular JSF2 and might be related to Spring, please tell me.

Bean:

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

Code:
&lt;h:form&gt;
    &lt;ice:panelGroup styleClass="crud-links"&gt;
        &lt;h:commandLink value="Delete" action="#{department.deleteDepartment}" /&gt;          
    &lt;/ice:panelGroup&gt;
&lt;/h:form&gt;
&lt;h:form&gt;
    &lt;ice:panelGroup&gt;
        &lt;ice:tree id="tree" value="#{department.model}" var="item" hideRootNode="false" hideNavigation="false" imageDir="./xmlhttp/css/xp/css-images/"&gt;
            &lt;ice:treeNode&gt;
                &lt;f:facet name="content"&gt;
                    &lt;ice:panelGroup style="display: inline"&gt;
                        &lt;ice:commandLink  value="#{item.userObject.text}"&gt;&lt;/ice:commandLink&gt;
                    &lt;/ice:panelGroup&gt;
                &lt;/f:facet&gt;
            &lt;/ice:treeNode&gt;
        &lt;/ice:tree&gt;
    &lt;/ice:panelGroup&gt;
&lt;/h:form&gt;

When page is loaded for first time the
Code:
model
object is populated with data, but when clicking delete button I notice that after clearing
Code:
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.

<strong>UPDATE</strong>- <strong>REQUIREMENT</strong>:

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 .