You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Davide Vecchi <dv...@amc.dk> on 2016/04/28 17:29:25 UTC

Calling a Link target from server-side code

Hi everybody,

This is the scenario:

I am in a component, and I have a string that contains an event name, f.ex.

                String eventName = "myEvent";

(but in reality it's not a constant).

So I also have a server-side event handler method for that event (in another component or in a page):

                public boolean onMyEvent()
                {
                                // Do stuff
                }

I use that string to create a Link object:

                Link link = componentResources.createEventLink(eventName);

Then I use that Link object as the href for some client-side elements, which when clicked cause my server-side event handler to get called.

This is all OK.

However I would also like to call that event handler programmatically, from my server side code, not in response to a client-side user action.

What is the proper way to go about that ?

RE: Calling a Link target from server-side code

Posted by Davide Vecchi <dv...@amc.dk>.
That is it, thank you. I had used it several times in the past but for some reason this time I went blank... It works great.


-----Original Message-----
From: Charlouze [mailto:me@charlouze.com] 
Sent: Thursday, April 28, 2016 17:57
To: Tapestry users <us...@tapestry.apache.org>
Subject: Re: Calling a Link target from server-side code

Hey !

You can trigger event with the ComponentResources service :
*componentResources.triggerEvent(String eventType, Object[] contextValues, ComponentEventCallback callback);*

I hope it'll help you.

Charles

Le jeu. 28 avr. 2016 à 17:29, Davide Vecchi <dv...@amc.dk> a écrit :

> Hi everybody,
>
> This is the scenario:
>
> I am in a component, and I have a string that contains an event name, f.ex.
>
>                 String eventName = "myEvent";
>
> (but in reality it's not a constant).
>
> So I also have a server-side event handler method for that event (in 
> another component or in a page):
>
>                 public boolean onMyEvent()
>                 {
>                                 // Do stuff
>                 }
>
> I use that string to create a Link object:
>
>                 Link link = 
> componentResources.createEventLink(eventName);
>
> Then I use that Link object as the href for some client-side elements, 
> which when clicked cause my server-side event handler to get called.
>
> This is all OK.
>
> However I would also like to call that event handler programmatically, 
> from my server side code, not in response to a client-side user action.
>
> What is the proper way to go about that ?
>

Re: Calling a Link target from server-side code

Posted by Charlouze <me...@charlouze.com>.
Hey !

You can trigger event with the ComponentResources service :
*componentResources.triggerEvent(String eventType, Object[] contextValues,
ComponentEventCallback callback);*

I hope it'll help you.

Charles

Le jeu. 28 avr. 2016 à 17:29, Davide Vecchi <dv...@amc.dk> a écrit :

> Hi everybody,
>
> This is the scenario:
>
> I am in a component, and I have a string that contains an event name, f.ex.
>
>                 String eventName = "myEvent";
>
> (but in reality it's not a constant).
>
> So I also have a server-side event handler method for that event (in
> another component or in a page):
>
>                 public boolean onMyEvent()
>                 {
>                                 // Do stuff
>                 }
>
> I use that string to create a Link object:
>
>                 Link link = componentResources.createEventLink(eventName);
>
> Then I use that Link object as the href for some client-side elements,
> which when clicked cause my server-side event handler to get called.
>
> This is all OK.
>
> However I would also like to call that event handler programmatically,
> from my server side code, not in response to a client-side user action.
>
> What is the proper way to go about that ?
>