Soumitri Pattnaik
Soumitri Pattnaik

Reputation: 3556

How to pass value from Javascript to Wicket?

I have Javascript method, that performs some business logic at client end and returns a values. Now I need this value in my wicket page. What is the best way to go about this?

P.S. I am using Wicket 7.

Upvotes: 0

Views: 736

Answers (3)

Rob Audenaerde
Rob Audenaerde

Reputation: 20019

You could write an AbstractAjaxBehaviour that calls your javascript function and passes it back with ajax to the callbackUrl

See the answer here here for more detail.

In the respond(AjaxRequestTarget target) you can update any component in the page that need updating.

For example, you could run a behavior that tests WebGL support via Javascript, pass it back to the Page via the Behavior and use the value to replace a placeholder or fallback Panel with a fancy WebGL version.

Upvotes: 2

Andrea Del Bene
Andrea Del Bene

Reputation: 2511

You might consider to use a custom resource. Once you have collected the user data with JavaScript, you can send them via ajax to the custom resource mounted at a specific path. Additional data processing can be done in the custom resource and you can display the result once the ajax request has finished.

Upvotes: 0

Mike Adamenko
Mike Adamenko

Reputation: 3002

Wicket components are rendered on the server side so you don't have access to them from JavaScript after a page was rendered.

If you want to send some data to the server just use Ajax request or submit the form.

Upvotes: 0

Related Questions