You can have it easier in Tapestry 5.4.2+, not having to pass the event URL from Java to JavaScript. From the example at tapestry.apache.org/ajax-and-zones.html#AjaxandZones-Invokingserver-sideeventhandlermethodsfromJavaScript, supposing you want to trigger a server-side event when clicking the <p id="result"> element:
@PublishEvent [ReturnType] yourEventHandlerMethod() { In the template of the component or page class above. <p id="result">(no result yet)</p> JavaScript: require(["t5/core/ajax", "jquery"], function (ajax, $) { // Creating a callback to be invoked with <p id="result"> is clicked. $('#result').click(function() { ajax('answer', { element: $('#result'), // This doesn't need to be the same element as the one two lines above // Callback called when the request is finished. // response.json is the object returned by the event handler method success: function(response) { $('#result').text(response.json.origin); } }); }); }); On Fri, Dec 14, 2018 at 2:08 PM Ilya Obshadko <ilya.obsha...@gmail.com> wrote: > That's actually quite easy: > > define(["jquery", "t5/core/utils", "t5/core/ajax", "t5/core/events"], > function($, utils, ajax, events) { > return function(spec) { > var $zoneElement = $('#' + spec.zoneElementId) > $zoneElement.trigger(events.zone.refresh, { url: > spec.zoneRefreshUrl }) > }; > }); > > And you can construct and pass the actual zoneRefreshUrl using > ComponentResources.createEventLink method when using > JavaScriptSupport.require. > Event handler method, in this case, is supposed do something like > ajaxResponseRenderer.addRender(zoneElement), or simply return injected > block. > > > On Fri, Dec 14, 2018 at 3:04 AM Christopher Dodunski < > chrisfromtapes...@christopher.net.nz> wrote: > > > Hi all, > > > > I had mistakenly thought that any event handler method could render a > > response through return type, whereas seemingly this is unique to events > > triggered by Tapestry's actionlink, eventlink and form components. > > > > I developed a filter pane component for limiting the number and (date) > > range of hibernate results displayed. The idea was for this pane to > > trigger a "filter" event - componentResources.triggerEvent("filter", > null, > > null) - causing the container to refresh the zone that contains the > > results. But invoking onFilter() produces the error: "This type of event > > does not support return values from event handler methods." > > > > What is the usual method for triggering events so that a handler method > > renders a response based on return type (zone body in my case)? > > > > I guess my handler method could rather respond to the "success" event > that > > bubbles up from the filter pane's internal form, as with beaneditform, > but > > this isn't an ideal or elegant approach in all situations. > > > > Regards, > > > > Chris. > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > > > -- > Ilya Obshadko > -- Thiago