I have a mixin that does this. It doesn't have to be a mixin though. I used
the urlencoder from TAP5-637 since space characters and such tend to make
things break. Basically you encoder a bunch of unique characters as the
context of the url server side, then replace it with whatever value you want
actually sent as the context.

@Import(stack="core",
library={"context:/js/urlencoder.js","context:/js/updater.js"})
public class Updater
{
  @Inject
  private JavaScriptSupport jsSupport;
  @Inject
  private ComponentResources componentResources;
  
  @InjectContainer
  private ClientElement element;

  void afterRender()
  {
    String replace = "0xDEADBEEF";
    String url = componentResources.createEventLink("change",
replace).toAbsoluteURI();
    jsSupport.addScript(String.format("new Updater ('%s','%s','%s');",
element.getClientId(), url, replace));
  }
}

//updater.js
var Updater = Class.create({
        initialize : function(elementId,url,urlReplace) {
                try {
                        var theSelect = this.theSelect = $(elementId);
                        this.theSelect.observe('change',
this.onChange.bindAsEventListener(this));
                        this.url = url;
                        this.urlReplace = urlReplace;
                } catch (ex) {
                        log(ex);
                }
        },
        onChange : function(e) {
                log('onChange');
                var v = URLEncoder.encode(this.theSelect.value);
                log(v);
                var url = this.url.replace(this.urlReplace,v);
                var _this = this;
                Tapestry.ajaxRequest(url);
        }
});


--
View this message in context: 
http://tapestry-users.832.n2.nabble.com/dynamically-changing-event-link-context-on-client-side-using-js-tp6216273p6218667.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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

Reply via email to