I didn't tried it but IMHO there are three options you can try:
- Instead of adding "onchange" by yourself, add
OnChangeAjaxBehavior
and make all work in wicket. Downside is server roundtrip on every event. - Add data-attributes (
AttributeModifier.append("data-param1", "foobar")
) to push your parameters into html and callajaxRequestTarget.appendJavaScript("attachOnChangeHandler()");
after the click event on the AjaxLink.attachOnChangeHandler()
should be your js function to add onchange handler to every item which needs it. And over data-attributes you can access your parameters. - Since Wicket 6: To avoid mixing to much js with Wicket, you could subscribe to one of the global AJAX events. The solution in your case would be almost the same as in 2. Just add a listener in js for "/ajax/call/success" (see if the call relates to your component by checking the id) and add the onchange handler there. This is IMHO the best solution without mixing custom js with Wicket.
The solution provided by @peterchon (attaching event handlers higher in the DOM than the elements which are going to be replaced by wicket) would work in every other case, but you have "onchange" which applies only to input, textarea and select elements.
BTW the page is "working" after refresh, since the whole page is rendered and browser can properly attach the handlers.