Wednesday, February 16, 2011

onConfigure for Wicket, use for business logic?

I asked this:

here is the best place to put code to initialize the model before a
page renders. I know of five options, but where do you normally put
this type of initialization.

Before a page renders, I want to set the data in my bean/model with
certain attributes that may only be specific to that page.

I think there are five options.

1. Add initialization logic in the constructor. This may work, but I
don't know if the constructor is called for every page call (E.g. when
the page is deserialized)
2. Add init logic in onBeforeRender. This works and it called for every
request? But is it the best place?
3. Add init logic in a "load" or "getmodel" method in
LoadableDetachableModel class?
4. Add init in previous page on onSubmit method or onEvent. (onSubmit()
{ initBeanInSession(); setResponsePage(); }
5. Pass a model to a panel or page constructor (using pageparameters?)

Are any of these best practices or preferred over the other.

(a) Page Constructor code with Loadable detachable model:

MyPage.java:
...
final Form form = new Form(FORM, new
CompoundPropertyModel(new LoadableDetachableModel() {

private static final long serialVersionUID = 1L;
@Override
protected MyBean load() {
final MyBean app = (MyBean) Session.get().getApp();

?????????????
?????????????
initialize here???????
?????????????
return app;
}
};
});

???
onBeforeRender() {
?? Add initiailize here
final MyBean app = (MyBean) Session.get().getApp();
app.setData(doSomeBusinessLogicHere)

}

or initModel?

/**
* Called once per request on components before they are about to be rendered.
* This method should be used to configure such things as visibility and enabled flags.
*/
@Override
protected void onConfigure() {
super.onConfigure();

// Call business logic and properly set email address.

}

No comments:

Post a Comment