On Fri, May 15, 2009 at 12:07 AM, Jeremy Thomerson
<[email protected]> wrote:
>
> Most java programmers know not to call overridable methods from the
> constructor as a general rule, although there are times when it could
> inadvertantly happen - which is why we need bug reports if you see
> that happening.
>
I've only been on the wicket list for a few months, and I can
understand the annoyance of bringing up a subject that's perhaps been
beaten to death, but to me that means the resulting consensus to be
documented in the wiki, rather than pointing users to "search the
list." So whatever comes out of this thread, I'll add it to the wiki
(unless it's already there, in which case I apologise.)
This isn't just a matter of whether Wicket internally calls
overridable methods.
What ends up happening (only in my experience) is that inheritance for
pages ends up needing you to create your own internal init() mechanism
in order to ensure that subclasses are ready to effectively override
methods for base class component creation. I'm not suggesting that
Wicket provide this type of init() mechanism, but in my experience it
is a pattern that crops up, and it should be documented as such. If
it is already documented, my apologies. If it's an anti-pattern,
what's the alternative?
public class Template extends WebPage {
public Template(PageParameters params) {
setupParams(params);
add(new Label("title",getTitle()));
}
pubilc void setupParams(PageParameters params) { }
public String getTitle() { return "Title should be overriden"; }
}
public class SpecificPage extends Template {
Object somethingCreatedBasedOnParams;
public SpecificPage(PageParameters params) {
super(params);
}
public void setupParams(PageParameters params) {
//set up somethingCreatedBasedOnParams
}
public String getTitle() {
return "A page about " + somethingCreatedBasedOnParams.getFoo();
}
}
This same pattern evolves in my experience even if you are using
panels for templating, because you need the base class to add() the
panel, and the subclass wants to override which panel to add, but it
can't know what it needs to know in the override unless an init method
has given it a chance to access PageParameters.
-Clint
>
>
> On Fri, May 15, 2009 at 12:01 AM, Vladimir K <[email protected]> wrote:
>>
>> Martijn,
>>
>> here Java is not safe as a language. Yo're able to invoke overrided methods
>> on non-completely constructed objects.
>>
>> from my perspective it is a regular case in Wicket:
>>
>> class SampleComponent extends ... {
>> String parameter;
>>
>> SampleComponent(String id, String parameter) {
>> super(id);
>> this.parameter = parameter;
>> }
>>
>> // method is called from within superconstructor
>> �...@override
>> void createAdditionalComponents(RepeatingView rv) {
>> useSomehow(parameter);
>> }
>> }
>>
>> I know two approaches to work around:
>> - onBeforeRender
>> - a closure as a constructor formal parameter.
>>
>> But the latter does not help with built-in components.
>>
>> If Wicket does not help us with adding appropriate method for
>> second-step-initialization it should document it in wiki, javadoc and books
>> "dear user, when overriding methods, beware using of yet unassigned
>> constructor parameters". Hmm ... sounds stupid :)
>>
>>
>> Martijn Dashorst wrote:
>>>
>>> This has been discussed till death previously and we have excluded it
>>> from our roadmap. We will never have an init() method for components.
>>> Gossling gave us a Constructor to initialize your Objects.
>>>
>>> Search and read the archives if you want more information on the subject.
>>>
>>> Martijn
>>>
>>> On Fri, May 15, 2009 at 12:36 AM, Juan G. Arias <[email protected]>
>>> wrote:
>>>> It would be very nice to add a new phase for component creation, like I
>>>> said, an init() or createContent().
>>>> Is there a JIRA issue for that?
>>>> If yes, I will vote for it and suggest to change the name to something
>>>> _not_
>>>> related to the rendre phase.
>>>>
>>>> Thanks!
>>>> Juan
>>>>
>>>>
>>>> On Thu, May 14, 2009 at 3:31 PM, Daniel Stoch
>>>> <[email protected]>wrote:
>>>>
>>>>> I think you can use hasBeenRendered() method instead of custom boolean
>>>>> flag.
>>>>>
>>>>> --
>>>>> Daniel
>>>>>
>>>>> On 2009-05-14, at 20:15, Jeremy Thomerson wrote:
>>>>>
>>>>> You could probably do it in onBeforeRender - but you would need to
>>>>>> keep a boolean flag to check if it's the first render so that you
>>>>>> don't recreate them on a second render.... There was talking of
>>>>>> adding an onBeforeFirstRender method, but I don't think it's happened
>>>>>> yet - you could look for the method to see if I'm wrong.
>>>>>>
>>>>>> --
>>>>>> Jeremy Thomerson
>>>>>> http://www.wickettraining.com
>>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [email protected]
>>>>> For additional commands, e-mail: [email protected]
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Become a Wicket expert, learn from the best: http://wicketinaction.com
>>> Apache Wicket 1.3.5 is released
>>> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Component-creation-and-initialization-tp23545666p23553458.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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]
>
>
--
Clint Popetz
http://42lines.net
Scalable Web Application Development
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]