سؤال

I have a fairly simple question, but I'm unable to find a working answer. I'm using javascript in my HTML file for a page that is taking input from the page and giving me back a string of a jSON object. All that I want to do is take this string and put it in a Java string. I can do things like

target.appendJavaScript("s=getString();");
target.appendJavaScript("alert(s);")

which give me the desired information in the alert. But how do I get s into a Java string?

I have tried the following

StringValue temp = RequestCycle.get().getRequest().getQueryParameters().getParameterValue("s");
info(temp.toString());

And other variations like getRequestParameters(), but I get nulls on temp. These actions are inside an AjaxFallbackButton's onSubmit.

Any advice on how to get a javascript var in Java?

هل كانت مفيدة؟

المحلول

Although I would still like to know more about sharing variables between Java and Javascript in HTML, my case was solved thanks to Wicket. The value that I was retrieving with s=getString() was already accessible in a HiddenField, and so I simply needed to get it a wicket:id in the HTML and add it with a property model in the Java. Hopefully this might help someone else in the future.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top