1
votes

We are using the PrimeFaces 4.0 + spring 4 on Tomcat 7.

I go to PrimeFaces show case, open the wizard, type first name and last name hit the next button. Then I select other menus from left panel ( like AutoComplete ) I go back to wizard the first name and last name fields are clear. That is what I expected.

I developed a wizard same as above but every time I come back to wizard page the wizard still holds the previously entered value and is not reset.

My managed bean is as below ( I have used ViewScoped no SessionScope which mentioned in documents):

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@Named
@ViewScoped
public class AccountController {

     @Valid
     private Account account = new Account()

     //Setters and getters    
}

Edited:

I found that the problem is for integration of JSF and Spring. When I remove the @Named and use @ManagedBean it works fine. Any comments?!

1

1 Answers

1
votes

Spring does not have a built in support for JSF ViewScope, but you can add this scope to JSF as:

public class ViewScope implements Scope {

    public Object get(String name, ObjectFactory<?> objectFactory) {
        Map<String, Object> viewMap = FacesContext.getCurrentInstance()
                .getViewRoot().getViewMap();

        if (viewMap.containsKey(name)) {
            return viewMap.get(name);
        } else {
            Object object = objectFactory.getObject();
            viewMap.put(name, object);

            return object;
        }
    }

    public Object remove(String name) {
        return FacesContext.getCurrentInstance().getViewRoot().getViewMap()
                .remove(name);
    }

    public String getConversationId() {
        return null;
    }

    public void registerDestructionCallback(String name, Runnable callback) {
        // Not supported
    }

    public Object resolveContextualObject(String key) {
        return null;
    }
}

Please refer to http://blog.primefaces.org/?p=702

And in your applicationConetext.xml

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
    <property name="scopes">
        <map>
        <entry key="view">
                <bean class="utils.ViewScope" />
        </entry>
        </map>
    </property>
</bean>

And finally:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@Named
@ViewScoped
@Scope("view")
public class AccountController {

     @Valid
     private Account account = new Account()

     //Setters and getters    
}