-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>> 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";
    }
  }
}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+kYrIACgkQbmZsMyUPuXSQgQCfSSUfNcvM34XVmHcosQu7x2DT
BPoAnR7V/7DjsQwyZB0fyvasOfF+UEX+
=xclp
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to