Pergunta

I have a SessionScoped ManagedBean. I want to reset all value of this bean. I'm using JSF 2.1.0-b03

@ManagedBean(name = "myBean")
@SessionScoped
public class MyBean implements Serializable {
    private static final long serialVersionUID = 1L;
    private String name;
}

Now, I've the method, which resets all value to null. But I don't like this solution.

private void unboundValue() {
    name= null;
}

How can I unbound value from SessionScoped ManagedBean?

Foi útil?

Solução

Manual reset seems the proper way. If you want to invalidate the whole session, not just one bean, then call session.invalidate(). If it's just one bean, the manual field reset is ok.

Outras dicas

I think you could remove the SessionScoped managedbean from the ExternalContext's sessionmap. The next time the bean get's accessed a new one will be created with default values, or you just create a new bean and insert it into the session map and therefore replace the old one. Of course the procedure is a little overhead, but if you have lots of values which needs to get resettet, that could be one solution.

Otherwise you would need some kind of reset/unboundValue() method like you stated already.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top