You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Kanze <pe...@gmail.com> on 2009/03/25 12:10:37 UTC

T5: onActivate called twice

Hello
I have a pagelink that point to this /products/computer/5

In my Products.java I have two onActivate methods. See below.
When I click the pageLink I can see that both onActivate are called.
Because this is printed to the output console:

onActivate(String categoryName, int pageNr)
onActivate: (String categoryName)

Can somebody explain this?
I would expect only public void onActivate(String categoryName, int pageNr)
to be called, because the context has 2 parameters.

greetz,
Peter


public void onActivate(String categoryName) {
System.out.println("onActivate: (String categoryName)");
}
public void onActivate(String categoryName, int pageNr) {
System.out.println("onActivate(String categoryName, int pageNr)");
}

Re: T5: onActivate called twice

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
As Andy already pointed, this is normal Tapestry behaviour.
When you have more than onActivate() method, I recommend the use of a
single method receiving an EventContext
(http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/EventContext.html):

onActivate(EventContext event) {

    if (event.getCount() == 1) {
        String categoryName = event.get(String.class, 0);
    }
    if (event.getCount() == 2) {
        String categoryName = event.get(String.class, 0);
        int pageNumber = event.get(Integer.class, 1);
    }

}

-- 
Thiago

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


RE: T5: onActivate called twice

Posted by "Blower, Andy" <An...@proquest.co.uk>.
Taken from http://tapestry.apache.org/tapestry5.1/guide/event.html and should answer your question I think.


Multiple Method Matches

In some cases, you may have multiple event methods match a single event.

The order is as follows:

    * Base class methods before sub-class methods.
    * Matching methods within a class in alphabetical order.
    * For a single method name with multiple overrides, by number of parameters, descending.

There's only rare cases where it makes sense for more than one method to handle an event.

When a sub-class overrides an event handler method of a base class, the event handler method is only invoked once, along with any other base class methods. The subclass can change the implementation of the base class method via an override, but can't change the timing of when that method is invoked. See TAPESTRY-2311.


> -----Original Message-----
> From: Peter Kanze [mailto:peterkanze@gmail.com]
> Sent: 25 March 2009 11:11
> To: Tapestry users
> Subject: T5: onActivate called twice
> 
> Hello
> I have a pagelink that point to this /products/computer/5
> 
> In my Products.java I have two onActivate methods. See below.
> When I click the pageLink I can see that both onActivate are called.
> Because this is printed to the output console:
> 
> onActivate(String categoryName, int pageNr)
> onActivate: (String categoryName)
> 
> Can somebody explain this?
> I would expect only public void onActivate(String categoryName, int
> pageNr)
> to be called, because the context has 2 parameters.
> 
> greetz,
> Peter
> 
> 
> public void onActivate(String categoryName) {
> System.out.println("onActivate: (String categoryName)");
> }
> public void onActivate(String categoryName, int pageNr) {
> System.out.println("onActivate(String categoryName, int pageNr)");
> }


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


Re: T5: onActivate called twice

Posted by Robert Zeigler <ro...@scazdl.org>.
Already pointed out that this is expected. But you can bypass this  
behavior.
Make your two-parameter method return "true" on successful processing;  
then your 1-parameter method won't be called.

Robert

On Mar 25, 2009, at 3/256:10 AM , Peter Kanze wrote:

> Hello
> I have a pagelink that point to this /products/computer/5
>
> In my Products.java I have two onActivate methods. See below.
> When I click the pageLink I can see that both onActivate are called.
> Because this is printed to the output console:
>
> onActivate(String categoryName, int pageNr)
> onActivate: (String categoryName)
>
> Can somebody explain this?
> I would expect only public void onActivate(String categoryName, int  
> pageNr)
> to be called, because the context has 2 parameters.
>
> greetz,
> Peter
>
>
> public void onActivate(String categoryName) {
> System.out.println("onActivate: (String categoryName)");
> }
> public void onActivate(String categoryName, int pageNr) {
> System.out.println("onActivate(String categoryName, int pageNr)");
> }


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