0

First of all I want to mention that I am a beginner when it comes to js and wicket.

I am trying to retrieve a variable that is defined in javascript on my page. I want to retrieve this variable when an event is triggered on my page.

I use this code to retrieve the variable but it is not working (this is my wicket panel java class):

...
    add(new AjaxEventBehavior("onclick") {
        private static final long serialVersionUID = 1L;

        protected void onEvent(AjaxRequestTarget target) {
        if(target != null) {
                String value = RequestCycle.get().getRequest().getParameter("i");
            }
        }
    });  

Could someone point me in the right direction?

Thank you in advance.

2 Answers 2

3

Have a read of this https://cwiki.apache.org/WICKET/calling-wicket-from-javascript.html. You need to pass your behavior's getCallbackUrl() to js and call it using Wicket.Ajax.get({ u: '${callbackUrl}' + '${args}' }).

Sign up to request clarification or add additional context in comments.

Comments

1

You will need to "post" the content of your variable to your behavior in order to be able to get it in your request parameters. You can do it easily with an AjaxCallDecorator(wicket < 6) or an AjaxCallListener (wicket >= 6).

I suggest you to understand what's going on with your application, Javascript variable can't be this easily retrieved by the Java side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.