Hi,
First I suggest you to create a factory class in charge of converting string to
instance :
Panel MyFactory.newComponent(String panelType, String id);
To implement the method, I see 2 ways:
1/ a list of if/else
if ("up".equals(panelType)) {
return new UserPanel(id);
}
if( "xx".equals(panelType)) {
...
}
2/ using your properties and java reflection (somethings like
String typeStr = props.get(panelType); //"up" -> "myPackage.UserPanel"
Class<? extends Panel> type = Class.forName(typeStr);
Constructor<? extends Panel> ctor = type.getConstructor(String.class);
ctor.newInstance(id);
both solutions have pro and cons :
1 2
+ - compile type check on type
+ - ide refactoring : rename class, package
- + hard code of mapping, but if the properties file is part of the
jar like .class : same issue need to rebuild to add mapping
+ - possibilite to have variation on constructor between class
+ - performance (IHMO) but depends of the size of the mapping
You could also use an IoC framework like spring to manage mapping and
constuction.
Regards
/david
darrengreer wrote:
First off, I am just starting out in both Java development, and wicket, so
I'm probably doing this way wrong. So, if anyone wants to correct my
methodologies, please do.
Here is the scenario. I have a bookmarkable page, that I want users to be
able to bookmark with page parameters. Those page parameters will
essentially point to dozens of potential "Panels". Those parameters also
will reference the name of the panels as stored in a properties file.
For example:
URL: http://domain/app/page/m/up
The "m" parameter contains the reference to module "up". The page component
will lookup "up" within the properties file, or multiple to pull:
-up=UserPanel
Now at this point, I want to add that value as an actual UserPanel to the
page. For example:
add(new UserPanel("contentPanel"));
That is where I am getting stuck. I know the value of "UserPanel" as a
string, but now sure how to then actually convert that so that I can
actually create a new UserPanel object, without having to hardcode just
that. This is probably more of a general Java understanding, than it is a
wicket problem. But, I was hoping anyone could point me in the right
direction, or explain to me how much easier this is to do using some wicket
feature I haven't figure out yet.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]