I’m trying to implement a form that I can reuse for adding or editing an object. I’ve noticed if I define a class extending Form that I have to declare the markup for all the form components in the HTML of the page where I’m creating an instance of this form.
I’ve tried placing a corresponding HTML file with my custom Form class in its package, but it doesn’t pick up the fact that the HTML goes with the Java class.
Basically I want the form to look exactly the same, but just to be able to override the onSubmit method of the form so I can use different values when I call setResponsePage for the form.
Wicket’s
Formdoesn’t support the same pattern of aligning with corresponding markup that many other wicket component classes do.When I want to do something like this, I wrap the form in a
Panelsubclass, put the form markup in the corresponding markup for that class, and can then include the panel in multiple pages without having to duplicate the markup.If you have multiple forms with the same markup, you can also either pass the form itself into the panel as a parameter, or have logic in the panel code that decides which variant to use.
Another possibility for your specific purpose is to pass the response page as a parameter on creating the form and then if that’s the only difference you don’t need to create two forms.