3

I have something I do not understand in Wicket. I created an AJAX Button with an override method onSubmit() linked with my HTML page. Once I press the button the method is not call.

Here the JAVA code:

  AjaxButton savebutton = (AjaxButton) new AjaxButton("save_ext", form) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            super.onError(target, form); //To change body of generated methods, choose Tools | Templates.
            System.out.println("save button ajax error");
        }

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {

             System.out.println("save form");
    }.setOutputMarkupId(true);

form.add(savebutton);

Here the HTML:

<button type="submit" value="save" wicket:id="save_ext" class="btn btn-success" id="buttonSave_ext" onclick="saveFunction()">Save</button>

Do you have an idea how to solve the problem.

Thanks

  • I have the same issue now, if you remove `onclick` in the button tag. Does it work? But mine does not have `onclick` but still I cannot reach `onSubmit()`. It sends requests when I click the button, but never reaches `onSubmit()` code. – Borgy Manotoy Dec 07 '22 at 02:43
  • Oh this thread is too old. Sorry, my project is using old wicket 6.3. I find it weird since I do not get any errors (dev tools console, it sends request when I click button submit), but I cannot hit `onSubmit()`. Too bad debug mode does not work on my IDE now. – Borgy Manotoy Dec 07 '22 at 02:45

1 Answers1

0

Check in DevTools/Firebug whether there is an Ajax request made by clicking on the button. I see you have a "onclick" function in your markup. If it returns false then the other event listeners won't be executed, i.e. Wicket's click listener won't fire the Ajax call to notify the server side.

martin-g
  • 17,243
  • 2
  • 23
  • 35
  • I checked, I have IBehaviourListener. When I press the button, I do not see AjaxRequest but my javascript function work and returns true. How can I have an Ajax Request? – user3774233 Apr 30 '15 at 09:36
  • First try by removing your "onclick". If this doesn't help then put a breakpoint at https://github.com/apache/wicket/blob/wicket-6.x/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js#L554 and see where it goes. Maybe some precondition?! – martin-g Apr 30 '15 at 13:17
  • I tried to remove onclick tag and still the same problem. I checked on Firebug I receive only one GET IBehaviourListener and no POST. What does it mean? Should I receive a POST? – user3774233 Apr 30 '15 at 13:49