This is my first time with wicket, so please bear with me.
Most examples in wicket show how with a wicket id you can automagically replace the inner HTML with different things. Using this knowledge I’ve hand written a form in HTML with lots of formatting and JQuery for different things, and only using Wicket to autogenerate the info for 2 select boxes. However when I try to parse the submitted information on the Wicket side, I get confused.
The only way I’ve figured out that’s easy is using RequestCycle.get().getRequest().getRequestParameters(). to get all the passed info. It works, but I don’t think that’s the ideal way to use Wicket. There also seems to be a way with request handlers but I have no idea where to start, especially since a lot of documentation is out of date with the new 6.0.0 release.
What is the way I’m supposed to use Wicket with forms? Do I hand write most of the form, only let Wicket autogenerate some of the info, and use RequestCycle? Do I write a skeleton form, have Wicket autogenerate the rest, and use lots of submit handlers? Where is this documented in an easy to understand beginner tutorial?
Note: My form has several fields that are created dynamically (think “click here to add more options”) and is submitted in the background with AJAX, verified, then cleared. This might complicate the Wicket side of things, but is a functional requirement
With Wicket you can think of HTML markup as if it was a template. Markup is actually almost-standard HTML. You can (and should) define
wicket:idattributes for everything that will have certain behavior or logic attached (forms, buttons, links), or require some server-side processing (such as form components or nested custom components or panels). Everything else will be output in the response as it is in the markup.Wicket will handle form submission and process the request for you. In Wicket, form components are usually defined server-side, and added to a
Formcomponent. In theFormcomponent’sonSubmit(), Wicket will have already processed the request, and the submitted values will be available in theFormComponent‘s Models.So, the ideal way for Wicket to handle form submission would involve the server-side creation of any components in the form.
The following Wicket Examples page shows a basic
Formwith someFormComponentsin it: Wicket Examples – forminput. You can even see its source code.Also, you might find the following Wicket wiki page useful: How to do things in Wicket – Forms.
Regarding dynamic component creation, whenever a new dynamic component has to be created, you could for instance make an Ajax request that creates the component server side (wrapped in a
ListView, for example), and get markup refreshed in the ajax callback.There’s an example of such a list here: Wicket in action – Building a ListEditor form component
Just to add, I found the Wicket in Action book to be an excellent resource for learning Wicket. Chapter 6 – Processing user input using forms elaborates on the subject.