On 19/07/2012 17:01, divad91 wrote:
Hi,
I am new to Wicket. I'm working on a multi province web application.
The goal is to use the same web application for all provinces.
CSS and some business logic will differ for each province.
I want to know the best ways to instantiate my layout components in my base
page.
(Using markup inheritance for page composition)
* Each layout component could be subclassed.
public class BasePage extends WebPage {
public BasePage() {
// Want to know the best way to instanciate
// HeaderXXX or HeaderYYY for example base on the province.
add(new Header());
add(new SideBar());
add(new Footer());
}
}
My BasePage is in a common maven module.
Each province subclassed pages and components are in a different maven
module.
I read that using factories to instanciate components was not a good idea
(http://blog.comsysto.com/2011/05/09/apache-wicket-best-practices-2/)
Do you have a better approach to accomplish this?
Hi David,
Generally, you would use (potentially abstract) factory methods to
create you overridable components.
So:
public abstract class BasePage
{
public BasePage(){}
// these are the factory methods to create the components.
// I like to use the prefix "createNew", you can change.
protected abstract Component createNewHeader(String componentId);
protected abstract Component createNewSideBar(String componentId);
protected abstract Component createNewFooter(String componentId);
// Then add the components in onInitialize().
// onInitialize() is much under used. It allows us to call overridden method
// outside of the constructor.
@Override
public void onInitialize()
{
super.onInitialize();
add(createNewHeader("header"));
add(createNewSideBar("sideBar"));
add(createNewFooter("footer"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]