You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Pete Poulos <pe...@gmail.com> on 2009/07/16 06:38:56 UTC

How should missing page context be handled?

lets say I have a view product page which expects the product id in
its context.  The URL for this might look like
"http://app-root/product/view/12345".

What is the best way to detect if the user modifies their URL to
"http://app-root/product/view" without the context?

The only way I've found is to do something like the following:

public class ViewProduct {

   @Property
   private Product product;

   Object onActivate() {
      if( product == null ) {
         return RedirectPage.class;
      }
      return null;
   }

   void onActivate( Product product ) {
      this.product = product;
   }

}

I found that only onActivate() gets called when the context is
missing, but that both of them are called if the context is present.
The order of exection is as follows:

onActivate(Product)
onActivate()

This leads me into a second question:  Is this the way it is supposed
to behave (it seems wierd to me), and if so why is this the preferred
behavior?

Also, returning to my original question, is this the best way to
handle pages without context?  It seems like there should be a better
way.

Thanks in advance,
pete.poulos@gmail.com

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


Re: How should missing page context be handled?

Posted by Felix Gonschorek <fe...@ggmedia.net>.
hi,

you instead of two onActivate methods with different parameter count, you can 
use a single method with a EventContext parameter. With this object, you can get 
the number of activation context parameters and it has handy methods to obtain 
the parameters (coerced to the desired type - in your case "Product").

felix

Pete Poulos schrieb:
> lets say I have a view product page which expects the product id in
> its context.  The URL for this might look like
> "http://app-root/product/view/12345".
> 
> What is the best way to detect if the user modifies their URL to
> "http://app-root/product/view" without the context?
> 
> The only way I've found is to do something like the following:
> 
> public class ViewProduct {
> 
>    @Property
>    private Product product;
> 
>    Object onActivate() {
>       if( product == null ) {
>          return RedirectPage.class;
>       }
>       return null;
>    }
> 
>    void onActivate( Product product ) {
>       this.product = product;
>    }
> 
> }
> 
> I found that only onActivate() gets called when the context is
> missing, but that both of them are called if the context is present.
> The order of exection is as follows:
> 
> onActivate(Product)
> onActivate()
> 
> This leads me into a second question:  Is this the way it is supposed
> to behave (it seems wierd to me), and if so why is this the preferred
> behavior?
> 
> Also, returning to my original question, is this the best way to
> handle pages without context?  It seems like there should be a better
> way.
> 
> Thanks in advance,
> pete.poulos@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

-- 
Felix Gonschorek
ggmedia

Kirchstr. 18
69115 Heidelberg

Tel:   +49 6221 187 44 10
Fax:   +49 6221 187 44 99
Mobil: +49 176 2234 1338

felix@ggmedia.net
http://www.ggmedia.net

Vertretungsberechtigte Gesellschafter:
Felix Gonschorek & Jochen Greiner

Umsatzsteuer-Identifikationsnummer
gemäß § 27a Umsatzsteuergesetz:
DE232906440

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