You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Julien Martin <ba...@gmail.com> on 2011/08/02 17:06:05 UTC

Specifying several event constants for the @OnEvent annotation?

Hello,
I need for a method to be called upon several events (e.g. ACTIVATE and
ACTION).
I tried the following:

*    @OnEvent(value = {EventConstants.ACTIVATE, EventConstants.ACTION})
    void loadJobPostings() {
        jobPostings = service.loadJobPostings();
    }
*
and it does not work/compile unfortunately. Am I missing something?
Can anyone please help?
Regards,
Julien.

Re: Specifying several event constants for the @OnEvent annotation?

Posted by Julien Martin <ba...@gmail.com>.
Thank you all. I am then going to use a private method invoked by both
public methods.
Regards,
Julien.

2011/8/3 Howard Lewis Ship <hl...@gmail.com>

> -1
>
> Thiago had the right solution.  Further, the second event
> ("fromMyAjaxEvent") will occur after the "activate" event itself
> (assuming that the Ajax-request originating component is on the same
> page).
>
> It is very much an exception to the rule to have multiple events
> handled by the same method. It is occasionally useful to have a single
> method handle events from multiple component ids (by exploding the
> "from" portion of the method name).
>
> On Tue, Aug 2, 2011 at 4:03 PM, Taha Hafeez <ta...@gmail.com>
> wrote:
> > How about having a new annotation ??
> >
> > @OnEvents(
> >   {
> >      @OnEvent(...), @OnEvent(...)
> >   })
> >
> >
> > On Wed, Aug 3, 2011 at 4:22 AM, nillehammer
> > <ta...@winfonet.eu> wrote:
> >> You could implement one method that is called by your two event
> handlers.
> >> E.g.
> >>
> >> @OnEvent(EventConstants.ACTIVATE)
> >> final void callEventHandlerFromActivate() {
> >>  this.doTheWork();
> >> }
> >>
> >> @OnEvent("yourAjaxEvent")
> >> final void callEventHandlerFromMyAjaxEvent() {
> >>  this.doTheWork();
> >> }
> >>
> >> private final void doTheWork() {
> >> ...
> >> }
> >>
> >>
> >> -----
> >> http://www.winfonet.eu
> >> --
> >> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Specifying-several-event-constants-for-the-OnEvent-annotation-tp4659025p4660584.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> >
> > --
> >
> > regards
> >
> > Taha Hafeez Siddiqi (tawus)
> > http://tawus.wordpress.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Specifying several event constants for the @OnEvent annotation?

Posted by Howard Lewis Ship <hl...@gmail.com>.
-1

Thiago had the right solution.  Further, the second event
("fromMyAjaxEvent") will occur after the "activate" event itself
(assuming that the Ajax-request originating component is on the same
page).

It is very much an exception to the rule to have multiple events
handled by the same method. It is occasionally useful to have a single
method handle events from multiple component ids (by exploding the
"from" portion of the method name).

On Tue, Aug 2, 2011 at 4:03 PM, Taha Hafeez <ta...@gmail.com> wrote:
> How about having a new annotation ??
>
> @OnEvents(
>   {
>      @OnEvent(...), @OnEvent(...)
>   })
>
>
> On Wed, Aug 3, 2011 at 4:22 AM, nillehammer
> <ta...@winfonet.eu> wrote:
>> You could implement one method that is called by your two event handlers.
>> E.g.
>>
>> @OnEvent(EventConstants.ACTIVATE)
>> final void callEventHandlerFromActivate() {
>>  this.doTheWork();
>> }
>>
>> @OnEvent("yourAjaxEvent")
>> final void callEventHandlerFromMyAjaxEvent() {
>>  this.doTheWork();
>> }
>>
>> private final void doTheWork() {
>> ...
>> }
>>
>>
>> -----
>> http://www.winfonet.eu
>> --
>> View this message in context: http://tapestry.1045711.n5.nabble.com/Specifying-several-event-constants-for-the-OnEvent-annotation-tp4659025p4660584.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> --
>
> regards
>
> Taha Hafeez Siddiqi (tawus)
> http://tawus.wordpress.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Specifying several event constants for the @OnEvent annotation?

Posted by Taha Hafeez <ta...@gmail.com>.
How about having a new annotation ??

@OnEvents(
   {
      @OnEvent(...), @OnEvent(...)
   })


On Wed, Aug 3, 2011 at 4:22 AM, nillehammer
<ta...@winfonet.eu> wrote:
> You could implement one method that is called by your two event handlers.
> E.g.
>
> @OnEvent(EventConstants.ACTIVATE)
> final void callEventHandlerFromActivate() {
>  this.doTheWork();
> }
>
> @OnEvent("yourAjaxEvent")
> final void callEventHandlerFromMyAjaxEvent() {
>  this.doTheWork();
> }
>
> private final void doTheWork() {
> ...
> }
>
>
> -----
> http://www.winfonet.eu
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Specifying-several-event-constants-for-the-OnEvent-annotation-tp4659025p4660584.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 

regards

Taha Hafeez Siddiqi (tawus)
http://tawus.wordpress.com

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


Re: Specifying several event constants for the @OnEvent annotation?

Posted by nillehammer <ta...@winfonet.eu>.
You could implement one method that is called by your two event handlers.
E.g.

@OnEvent(EventConstants.ACTIVATE)
final void callEventHandlerFromActivate() {
 this.doTheWork();
}

@OnEvent("yourAjaxEvent")
final void callEventHandlerFromMyAjaxEvent() {
 this.doTheWork();
}

private final void doTheWork() {
...
}


-----
http://www.winfonet.eu
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Specifying-several-event-constants-for-the-OnEvent-annotation-tp4659025p4660584.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Specifying several event constants for the @OnEvent annotation?

Posted by Julien Martin <ba...@gmail.com>.
Hello Igor,
I need this method to be called
1. when the page is activated (for a normal render)
2. and also when an ajax method is called (for an ajax render).
Is this possible?
Regards,
Julien.

2011/8/2 Igor Drobiazko <ig...@gmail.com>

> If the handler methods for two different events are same, then you probably
> need only a single event.
>
> BTW: Firing activate event might cause unexpected behavior as activate is
> already "reserved" by Tapestry.
>
> On Tue, Aug 2, 2011 at 5:06 PM, Julien Martin <ba...@gmail.com> wrote:
>
> > Hello,
> > I need for a method to be called upon several events (e.g. ACTIVATE and
> > ACTION).
> > I tried the following:
> >
> > *    @OnEvent(value = {EventConstants.ACTIVATE, EventConstants.ACTION})
> >    void loadJobPostings() {
> >        jobPostings = service.loadJobPostings();
> >    }
> > *
> > and it does not work/compile unfortunately. Am I missing something?
> > Can anyone please help?
> > Regards,
> > Julien.
> >
>
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>

Re: Specifying several event constants for the @OnEvent annotation?

Posted by Igor Drobiazko <ig...@gmail.com>.
If the handler methods for two different events are same, then you probably
need only a single event.

BTW: Firing activate event might cause unexpected behavior as activate is
already "reserved" by Tapestry.

On Tue, Aug 2, 2011 at 5:06 PM, Julien Martin <ba...@gmail.com> wrote:

> Hello,
> I need for a method to be called upon several events (e.g. ACTIVATE and
> ACTION).
> I tried the following:
>
> *    @OnEvent(value = {EventConstants.ACTIVATE, EventConstants.ACTION})
>    void loadJobPostings() {
>        jobPostings = service.loadJobPostings();
>    }
> *
> and it does not work/compile unfortunately. Am I missing something?
> Can anyone please help?
> Regards,
> Julien.
>



-- 
Best regards,

Igor Drobiazko
http://tapestry5.de