Hi Arno,
you can use the onActivate method in the following form:
class MyPage {
@Property String x;
public onActivate(EventContext context) {
if (context.getCount() > 0) {
this.x = context.get(String.class, 0);
}
else {
this.x = "default value";
}
}
}
the "onActivate" event handler with the single EventContext parameter
gets invoked in any case, regardless of the activation context parameter
count (gets invoked with no activation context too!).
nice to see you working with tapestry, i know your name from the german
java scene and appreciate, that tapestry gets increasingly attention in
germany ;)
felix
Am 05.05.2012 01:13, schrieb Arno Haase:
>>> Thanks for the help - onActivate() at least looks better than
>>> all ideas I had come up with. It still does not seem like an
>>> elegant, intuitive solution to me.
>
>> Why not elegant and intuitive? To me, they are. :) Just curious.
>> ;)
>
> If a page has optional context parameters, my understanding is that
> the way to implement that is to write several onActivate() methods
> with different numbers of parameters.
>
> Anyway, if there are several onActivate() methods they are all called,
> starting with the method with the most parameters. The only
> onActivate() method that is guaranteed to be called is the one with
> least parameters - in my code typically with no args.
>
> If I want to provide default values for context parameters, the
> initialization code must check whether they are already initialized,
> and assign default values only if they were not initialized by one of
> the other onActivate() methods (see code below).
>
> This even breaks in the (admittedly rare) case that one of the context
> parameters is coerced to null.
>
> Placing the initialization in pageAttached() or some other method that
> is guaranteed to be called exactly once and before any other stuff
> gets done allows straight-forward assignment of default values with
> less potential for subtle errors.
>
> Thanks for taking the time to look into this!
>
> - Arno
>
>
>
> class MyPage {
> @Property String x;
>
>
> public onActivate(String x) {
> this.x = x;
> }
>
> public onActivate() {
> // this check is the part I find less than elegant
> if (x == null) {
> x = "default value";
> }
> }
> }
>
>
> ---------------------------------------------------------------------
> 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]