[seam-dev] How to store data in contexts

Pete Muir pmuir at redhat.com
Thu May 7 07:10:43 EDT 2009


Dan and Shane raised the issue of how to store data directly in a  
context. 299 includes that facility:

@Current Manager manager;

    public void go(final String something) {
       // Store the String something in the session context
       Contextual<String> somethingContextual = new  
Contextual<String>() {
          public String create(CreationalContext<String> arg0) {
             System.out.println("Storing " + something + " in a  
context");
             return something;
          }

          public void destroy(String arg0) {
             System.out.println("Removing " + something + " from a  
context");
          }
       };
        
manager.getContext(ApplicationScoped.class).get(somethingContextual,  
new CreationalContext<String>() {
          public void push(String arg0) {
             // No-op, we don't need to deal with partially  
circularities here
          }
       });
    }

But often, if you are controlling the data object, it's better to use  
a bean to manage the data.

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




More information about the seam-dev mailing list