[seam-dev] How to "clear" something from a context

Pete Muir pmuir at redhat.com
Thu May 7 07:18:13 EDT 2009


This is something that was quite commonly needed in Seam, in part due  
to the use of outjection. As 299 doesn't support outjection, you need  
to use the manager pattern:

@SessionScoped
public class Login {

    public User user;

    public Login(@New User user) {
       // Initialize with an empty, new, user - the "not logged in" user
       this.user = user;
    }

    public void login(User user) {
       // Log in a real user
       this.user = user;
    }

    @Produces @LoggedIn @RequestScoped
    public User getCurrentUser() {
       return user;
    }

}

This is much cleaner :-)


--
Pete Muir
http://www.seamframework.org
http://in.relation.to/Bloggers/Pete




More information about the seam-dev mailing list