How do I call Java code from JavaScript code in Wicket?

acostache :

If I can do this, how do I call Java code (methods for instance) from within JavaScript code, in Wicket.

Antony Stubbs :

erk. The correct answer would be ajax call backs. You can either manually code the js to hook into the wicket js, or you can setup the callbacks from wicket components in java. For example, from AjaxLazyLoadPanel:

        component.add( new AbstractDefaultAjaxBehavior() {

        @Override
        protected void respond(AjaxRequestTarget target) {
            // your code here
        }

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead( response );
            response.renderOnDomReadyJavascript( getCallbackScript().toString() );
        }

        }

This example shows how to add call back code to any Component in Wicket. After the OnDomReady event fires in your browser, when loading a page, Wicket will cause it's js enging, to call back into your code, using Ajax, to the 'respond' method shown above, at which point you can execute Java code on the server, and potentially add components to the ajax target to be re-rendered.

To do it manually, from js, you can hook into wicket's system by printing out getCallbackScript().toString() to a attribute on a wicket component, which you'll then be able to access from js. Calling this url from js manually with wicket's wicketAjaxGet from wicket-ajax.js.

Check out the mailing list for lot's of conversation on this topic: http://www.nabble.com/Wicket-and-javascript-ts24336438.html#a24336438

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related