You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by MarcelS <su...@rogers.com> on 2012/01/25 07:33:41 UTC

OnEvent Action Handler Without Template

Greetings,

I've got a component which does not use a template (.tml) file, but rather
renders the component all in Java code using the render phases and
MarkupWriter.  The component includes an action event handler which is
envoked via JavaScript.  I've done this with other components, but they used
templates.  For this particular component I can not use a template.

My problem is that the action handler doesn't seem to be visible, even
though the event method is annotated with the OnEvent annotation.

For example (pseudo)

Component Class:


public String getClientId() { return 'MyComponent'; }

@OnEvent(component="myEventHandler", value=EventConstants.ACTION)

public Object myEventHandler() {

    &nbsp;&nbsp;&nbsp;&nbsp;return "Hello World"

}


JavaScript:


AjaxRequest.post('http://myurl.host.com/pagename/MyComponent.myEventHandler');


Does Tapestry require Action events to be declared in templates in order for
them to be invoked, or can I simply use the @OnEvent annotation to register
the event handler?

Thanks,

Marcel

--
View this message in context: http://tapestry.1045711.n5.nabble.com/OnEvent-Action-Handler-Without-Template-tp5429499p5429499.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

Re: OnEvent Action Handler Without Template

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 25 Jan 2012 04:33:41 -0200, MarcelS <su...@rogers.com> wrote:

> Greetings,

Hi!

> My problem is that the action handler doesn't seem to be visible, even
> though the event method is annotated with the OnEvent annotation.

You should create the event URL by @Inject'ing ComponentResources and  
using its createEventLink(String eventType, Object... context). That's  
exactly what EventLink and ActionLink use. Don't try to write this URLs by  
hand.

> Does Tapestry require Action events to be declared in templates in order  
> for them to be invoked, or can I simply use the @OnEvent annotation to  
> register the event handler?

Absolutely no.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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