...
Tapestry 5.4.2 introduced an API which makes it easy for server-side events to be invoked from JavaScript. On the server-side, you first need to annotate the event handler methods you want to expose with the @PublishEvent
annotation. Then, in JavaScript, all you need to do is to call the existing t5/core/ajax
function, but with slightly different parameters.
The t5/core/ajax
function has two parameters: url
and options
. Prior to Tapestry 5.4.2, the first one was difficult to get when doing AJAX requests to event handler methods. You needed to inject ComponentResources
in your component class, call componentResources.createEventLink()
for each event handler method, then pass all this information back to the browser through one of the JavaScriptSupport
methods. For Tapestry 5.4.2 and later, your JavaScript code only needs to know the event name (also called event type) and optionally indicate a DOM element to be used as a starting point for finding the event URL.
...