For objects that I get from session, I was trying to avoid accessing
them in the constructor but I wanted to setup my default model so that
they are pulled on the load method from a loadabledetachable model.
 
Which approach do you use?  Here are the three approaches,
 
(The code below is pseudo code, I am typing it out from memory).
 
** Scenario 1.  Add a call to the constructor.
 
public class SomePage extends Page {
 
   public SomePage() {
      ...
      ...
      final bigSessObjBean = WicketSession.get().getSomeObjBean();  <---
Access object from session in local constructor method scope.
      final Form x  = new Form("form", new
Model<ObjBean>(bigSessObjBean)) { <--- Obj bean as default model
           ...
      }
 
     or even...
 
     final Form x  = new Form("form") {
           ...
          onSubmit()  {      
               bigSessObjBean.getData(); <---- Here, accessing bigSess
Obj Bean
          }
      }
 
   }
 
}
 
 
** Scenario 2.  Use loadable detachable Model
 
public class SomePage extends Page {
 
   public SomePage() {
      ...
      ...
 
     l = new LoadableDetachableModel() {
        public Bean load() {
            return WicketSession.get().getSessBeanObj();
        }
     };
     final Form x  = new Form("form", l) {
           ...
          onSubmit()  {      
              getDefaultModel().getData(); <---- Here, accessing bigSess
Obj Bean
          }
      }
 
   }
 
}
 
** Scenario 3: Call the session get when you need it.
 
 final Form x  = new Form("form", l) { 
           ...
          onSubmit()  {      
            WicketSession.get().getSessBeanObj();.getData(); <---- Here,
accessing bigSess Obj Bean
          }
      }
 
Berlin Brown (POL)

Reply via email to