Wicket : Can a Panel or Component react on a form submit without any boilerplate code?

MRalwasser picture MRalwasser · Jun 2, 2010 · Viewed 9k times · Source

I am currently evaluating Wicket and I am trying to figure out how things work.

I have a question regarding form submit and panels (or other components). Imagine a custom wicket panel which contains a text field, doing as-you-type validation using ajax. This panel is added to a form. How can the Panel react a form submit (let's say because javascript/ajax is unavailable)?

I am currently only aware of one solution: calling a panel's method inside the Form onSubmit() method. But this seems not like a "reusable" approach here, because I have to add boilerplate code to every form's onSubmit() which contains the panel (and every developer which use the panel must know this).

So here comes my question: Is there any way that a Panel/Component can "detect" a form submit in some way? Or is there any other solution beside this?

Thank you.

Answer

Don Roby picture Don Roby · Jul 13, 2010

Make your panels implement org.apache.wicket.markup.html.form.IFormModelUpdateListener, and the updateModel() method should be called when the containing form is submitted and passes validation.

There's a good example of code using this by one of the wicket authors at the Wicket In Action blog.