Wicket: run JavaScript when a Form is submitted

If you don't want to go full Ajax as in m.bouali's answer, you can use a temporary behavior instead:

@Override
protected void onSubmit() {
    add(new Behavior() {
        protected boolean isTemporary(Component component) {
            // this behavior will be removed after rendering
            return true;
        }

        public void renderHead(Component component, IHeaderResponse response) {
            response.render(JavaScritpHeaderItem.forScript("..."));
        }
    });
});

I think the best way to do that is to add an AjaxSubmitLink to your form so you can call javascript code inside the onSubmit method:

HTML code:

<form wicket:id="uploadFrm">
    <input type="submit" wicket:id="ajaxSubmitLink" value="OK" />
</form>

JAVA code:

Form<RequestInfo> uploadFrm = new Form<RequestInfo>("uploadFrm", getModel());   
AjaxSubmitLink ajaxSubmitLink = new AjaxSubmitLink("ajaxSubmitLink", uploadFrm) {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
               target.appendJavaScript("you javascript");                          
            }

        };

        uploadFrm.add(ajaxSubmitLink);