There is absolutely nothing preventing you from implementing your own
method. Just don't declare the property. I do this /all/ the time for
models which don't change... (and even for ones that do; you just can't
"stash" the ones that do change frequently. So, the next question is:
what if you want a /persistent/ property, AND you want to initialize it?
There are two possible solutions. One is to implement
PageRenderListener. I used to use this technique a lot...
pageBeginRender(PageEvent event) {
if (getCustomModel() == null) {
setCustomModel(new MyModel());
}
}
Lately, however, I've been shying away from using it, because I tend to
do a fair amount of rendering using block/render block, often with the
render'ed blocks being contained in other pages than the rendering page
(which means that pageBeginRender doesn't get called on these
components). So, one alternative that I've used is to use wrappers...
<property-specification name="customModel" type="MyModel" persistent="yes">
public abstract MyModel getCustomModel();
public abstract void setCustomModel(MyModel m);
public MyModel getMyModel() {
if (getCustomModel() == null) {
setCustomModel(new MyModel());
}
return getCustomModel();
}
then, in your ognl reference, use myModel instead of customModel.
If you're into keeping your page/component classes concrete, then
instead of declaring the abstract accessors, you would do:
if (getProperty("customModel") == null) {
setProperty("customModel",new MyModel());
}
return getProperty("MyModel");
Robert
Olexandr Yuzikov wrote:
> Hi guys,
>
> I have a problem with initialization of a IPropertySelectionModel.
> I saw at
> http://jakarta.apache.org/tapestry/doc/ComponentReference/PropertySelection.
> html and there is a property-specification with name="itemSelectionModel":
>
> ---
> <property-specification name="itemSelectionModel" type="ItemSelectionModel"
> persistent="yes"/>
> ---
>
> This string makes impossible to write own getter which returns custom
> implementation of the IPropertySelection interface.
>
> Regards,
>
> Oleksandr Yuzikov.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]