To be able to manipulate the user-entered values, the onSubmit()
method of the wicket.markup.html.form.Form
method must be
overwritten. The onSubmit()
method of the PizzaForm
class follows:
protected void onSubmit() { PizzaModel pizzaModel = (PizzaModel) getModelObject(); setResponsePage(new WicketTestConfPage(pizzaModel)); }
getModelObject()
and
requestCycle.setResponsePage()
methods.
getModelObject()
method call obtains an instance of the Model object populated with the
user-entered values. The
requestCycle.setResponsePage()
directs the browser to a new page. The
WebPage
instance that the browser will be redirected to must have a constructor
taking an instance of the Model object as a parameter.
Here is the source for the confirmation page:
public class WicketTestConfPage extends WebPage
{
public WicketTestConfPage(PizzaModel pizzaModel)
{
super();
add(new Label("crust", pizzaModel.getCrust()));
add(new Label("pepperoni", new Boolean(pizzaModel.getPepperoni())
.toString()));
add(new Label("sausage", new Boolean(pizzaModel.getSausage()).toString()));
add(new Label("onions", new Boolean(pizzaModel.getOnions()).toString()));
add(new Label("greenPeppers", new Boolean(pizzaModel.getGreenPeppers())
.toString()));
add(new Label("comments", pizzaModel.getComments()));
}
}
Here are the relevant sections of the corresponding HTML file:
<table
style="text-align: left; width: 427px; height: 112px;" border="1"
cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td
style="font-weight: bold; text-align: right;">Crust:</td>
<td><span
wicket:id="crust">Hello</span></td>
</tr>
<tr>
<td
style="font-weight: bold; text-align: right;">Toppings:</td>
<td>Pepperoni: <span
wicket:id="pepperoni"></span>
Sausage: <span
wicket:id="sausage"></span> Onions: <span
wicket:id="onions"></span> Green
Peppers: <span
wicket:id="greenPeppers"></span></td>
</tr>
<tr>
<td
style="font-weight: bold; text-align: right;">Comments:</td>
<td><span
wicket:id="comments"></span></td>
</tr>
</tbody>
</table>
<span>
fields, these correspond to the labels in the
WicketTestConfPage
java class. You may notice some of the
<span>
tags have text inside them, this text will only be displayed in the
browser when mocking up the pages, when displayed from the Wicket
application, they will display whatever value the corresponding
Label
instances have.
Wicket provides the following advantages over other web application frameworks:
Thanks to Gregg Bolinger, Johan Compagner and Eelco Hillenius for providing valuable feedback.