You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com> on 2010/11/10 14:32:01 UTC
For objects out of session, work with directly or use loadable
detachable model
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)
Re: For objects out of session, work with directly or use loadable
detachable model
Posted by Igor Vaynberg <ig...@gmail.com>.
even though they are in session it is still better to use a detachable
model. if you dont you may end up with the instance in session and in
your page diverging on back button because wicket clones the page with
the page being the root not the session so it wont handle the
reference properly. the rule of thumb is that unless the lifecycle is
managed by the page use a model.
-igor
On Wed, Nov 10, 2010 at 5:32 AM, Brown, Berlin [GCG-PFS]
<Be...@primerica.com> wrote:
> 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)
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org