Re: [Announcement] New feature for Tapestry 5.4.2 and 5.5: easily call event handler methods from JavaScript

abangkis <[email protected]>
Newsgroups gmane.comp.java.tapestry.user
Message-ID <CAGqeSzX9BJv+PFk+6Z-anJvojFTopJ=A+63dVsUVkdt77v_h_Q@mail.gmail.com>
Hi. Thanks for the awesome improvement. I want to adopt it immediately. But
I've stumbled to one problem. How do I pass a parameter to the event?

Here's the onEvent method that will be invoked

@OnEvent("updateNodes")
void updateNodes(@RequestParameter(value = "param", allowBlank = false)
String param) {
    logger.debug("On update nodes {} ", param);
}

In the old way i could call it using

$('#saveChanges').click(function () {
    var my_param = {'example param'};

    routejs.jsClickCallback(tSpec.updateOrderEventLink, tSpec.zoneId,
JSON.stringify(my_param));
});

var jsClickCallback = function(listenerURI, zoneElementId, param) {
  var listenerURIWithValue = listenerURI;

  listenerURIWithValue = appendQueryStringParameter(listenerURIWithValue,
'param', param);

  zoneManager.deferredZoneUpdate(zoneElementId, listenerURIWithValue);
};

var appendQueryStringParameter = function(url, name, value) {
  if (url.indexOf('?') < 0) {
    url += '?'
  }
  else {
    url += '&';
  }
  value = escape(value);
  url += name + '=' + value;
  return url;
}

On Sun, Apr 23, 2017 at 6:04 AM, Thiago H. de Paula Figueiredo <
[email protected]> wrote:

> Cool! It's nice to see a feature I've wanted for so long already being
> adopted by users. Thanks for the example!
>
> On Fri, Apr 21, 2017 at 11:18 AM, Svein-Erik Løken <[email protected]>
> wrote:
>
> > The @PublishEvent was a big improvement 😊
> >
> >
> >
> > I am using it already. I have created a working demo. I really like that
> > it is so easy to stop hardcoding of event url.
> >
> >
> >
> >
> >
> > https://github.com/sveine/tapestry-multi-module-demo/
> > blob/master/module1-root/module1/src/main/java/com/demo/module1/pages/
> > PublishEventDemo.java
> >
> > https://github.com/sveine/tapestry-multi-module-demo/
> > blob/master/module1-root/module1/src/main/resources/
> > com/demo/module1/pages/PublishEventDemo.tml
> >
> > https://github.com/sveine/tapestry-multi-module-demo/
> > blob/master/module1-root/module1/src/main/resources/META-INF/modules/
> > publisheventdemo.js
> >
> > https://github.com/sveine/tapestry-multi-module-demo/
> > blob/master/core/src/main/resources/META-INF/modules/
> util/tapestryutil.js
> > (TapestryUtil.ajaxEvent)
> >
>
>
>
> --
> Thiago
>



-- 
http://www.mreunionlabs.net/ <http://www.mreunion-labs.net/>
twitter : @mreunionlabs @abangkis
page : https://plus.google.com/104168782385184990771
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.