On Mon, Jun 02, 2008 at 11:36:33PM -0400, Brill Pappin wrote:
> Ahh... But there in lines the real point.
>
> What happens 2 years down the road when you need to modify that component?
> A) if its not typed then you hunt around and try and find out what it was...
> Maybe you do a println of the fqn...
> B) its typed... Your done.
>
> Even the time it takes to "discover" the model has direct bearing on ROI
> (although a lot of developers tend not to think on it much, we all depend on
> it) and the stats (and experience) say 80% of your work is maintenance.
>
> So, forget the 20%, lets chew away some of that 80%.
>
> - Brill Pappin
>
If I create a custom component that needs a particular type of model,
I would absolutely used a typed model. That's precisely where generics
are useful. What I'm talking about is not custom components but regular
everyday usage like this:
WebMarkupContainer<Void> row = new WebMarkupContainer<Void>("row");
row.add(new Label<String>("nameLabel", new ResourceModel<String>("name")));
row.add(new TextField<String>("name"));
The type specifications on WebMarkupContainer, Label, and TextField buy
me nothing, because I never call getModel() or getModelObject() on them.
OTOH, suppose we don't genericize component. I can still realize the value
of typed models by simply storing my own model instead of using the
model property of Component:
public class MyPanel extends Panel {
private IModel<Widget> model;
public MyPanel(String id, IModel<Widget> model) {
this.model = model;
}
public IModel<Widget> getWidgetModel() {
return model;
}
public void someMethod() {
// Look ma, no cast!
getWidgetModel().getObject().frobnicate();
}
public void onDetach() {
super.onDetach();
model.detach();
}
}
Remembering to override onDetach is a bit of a drag, but I think overall
I'm in for less work doing this where it's needed than the noise created
where it's not needed with a genericized Component.
jk
---------------------------------------------------------------------
To unsubscribe, e-mail:
users-unsubscribe@...
For additional commands, e-mail:
users-help@...