Pregunta

I am migrating a Tapestry application from 5.3.7 (and got5) to the current beta release of 5.4. On one particular page I use quite a bit of custom jQuery logic, which causes a problem:

$(document).ready(function() {
        init();
        Event.observe("periodsZone", Tapestry.ZONE_UPDATED_EVENT, function(event) {
            init();
    });
});

What this does is call an init method to register my jQuery event handlers and re-register them after a zone update.

I'm not sure, if this is best practice in the first place (especially mixing up jQuery and Prototype). Anyway, it stopped working in 5.4. I tried to handle the event using jQuery:

$("myZone").on("t5:zone:update", function(event) {
    init();
});

but that does not work either.

What is the correct name of the zone update event in 5.4 and how can I handle it properly?

On a side note, is there already a documentation on how to use jQuery in Tapestry 5.4? Of course I don't expect a beta version to be perfectly documented, but maybe someone can still help me out here.

EDIT: I finally refactored my code to use the Trigger component and JavaScriptSupport.require (it basically works the same for 5.3 using JavaScriptSupport.addInitializerCall):

In my tml:

<t:trigger event="myEvent"/>

In my Java code:

public void onMyEvent()
{
    javaScriptSupport.require("my-module");
}

my-module.js:

define([ "jquery" ], function($) {
    return function() {
        // do my stuff
    }
}

Every time the zone, which includes the trigger, is initially loaded or updated, my JS code is executed.

I'm just very slowly getting an idea, what Tapestry allows you to do with its Javascript capabilities. So far, I love it!

¿Fue útil?

Solución

This may relate to your question, and provide access to jumpstart for version 5.4: OnEvent examples.

The correct name for zone update event seems to be "t5:zone:update".

More docs on T5.4 (latest version is now 5.4-beta-5) is on http://people.apache.org/~hlship/t5api/

people.apache.org/~hlship/t5api/coffeescript/events.html#section-16

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top