|
Page Edited :
WICKET :
Calling Wicket from _javascript_
Calling Wicket from _javascript_ has been edited by Niels Boeger (Jun 09, 2009). Content:This mini tutorial shows you how to call Wicket from _javascript_. It is based on an e-mail from Michael Sparer Setting up the Wicket response to the _javascript_ callAdd the AbstractDefaultAjaxBehavior to the component you'd like to call from _javascript_. You then have to override the respond method of AbstractDefaultAjaxBehavior to perform your actions and to append your changes to the response For example in your panel: final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() { protected void respond(final AjaxRequestTarget target) { target.add(new Label("foo", "Yeah I was just called from _javascript_!")); } }; add(behave);
Here is an example: _javascript_ function callWicket() { var wcall = wicketAjaxGet('$url$' + '$args$', function() { }, function() { }); } '$url$' is obtained from the method behave.getCallbackUrl(). If you paste the String returned from that method into your browser, you'll invoke the respond method, the same applies for the _javascript_ method. You can optionally add arguments by appending these to the URL string. They take the form &foo=bar. Obtaining the GET/POST arguments on the server sideOk, this is actually quite ugly, but you get the optional arguments in the response method like this: Java Map map = ((WebRequestCycle) RequestCycle.get()).getRequest().getParameterMap(); Alternatively, you can retrieve a single parameter by its key: Java String paramFoo = RequestCycle.get().getRequest().getParameter("foo"); |
Unsubscribe or edit your notifications preferences
