Ensode.net
Google
 

Home
Blog
Guides
Tips
Articles
Utilities
Reviews
About Us
Contact us


Facebook profile

XML

A First Look at the Wicket Framework
Bookmark and Share

Page 1 Page 2 Page 3 Page 4

All I had to do to bind the properties in the PizzaModel class to the fields in the HTML form was to add following line of code in the PizzaForm class:

setModel(new CompoundPropertyModel(pizzaModel));
The wicket.model.CompoundPropertyModel class takes care of populating the fields in the Model object (PizzaModel in this example) with the appropriate user-entered values.

Something that wasn't clear from the Wicket examples was how to populate the field in the Model object mapping to a drop down component in the html file. Here is what I had to do to make it work:
I had to write a new Model class to model the options in the drop down, for the test application, I wrote a new class called CrustType:

  
public class CrustType implements Serializable
{
  String id;
  String text;
  
  public CrustType()
  {
    super();
  }
  
  public CrustType(String crustName)
  {
    setId(crustName);
    setText(crustName);
  }
  public String getId()
  {
    return id;
  }
  public void setId(String id)
  {
    this.id = id;
  }
  public String getText()
  {
    return text;
  }
  public void setText(String value)
  {
    this.text = value;
  }
  @Override
  public String toString()
  {
    return getText();
  }
}
  
  

I then had to instantiate the wicket.markup.html.form.DropDownChoice , which is the Wicket component used to map to an html <select> field (more commonly called a drop down), using the following constructor:
public DropDownChoice(java.lang.String id,
                      IModel model,
                      IModel choices,
                      IChoiceRenderer renderer)

The parameters I had to pass to make it all work together are as follows:
    crustDropDown = new DropDownChoice(
        "crust",new PropertyModel(pizzaModel, "crust"), Arrays
        .asList(new CrustType[]
                              { new CrustType("Thin & Crispy"), 
                                new CrustType("Hand Tossed"),
                                new CrustType("Pan Pizza") }), 
                                new ChoiceRenderer("text", "id"));

pizzaModel is the instance of the Model object that maps to the HTML form. "crust" is the name of the property in the model that will hold the value the user selected in the drop down. wicket.markup.html.form.ChoiceRenderer implements the wicket.markup.html.form.IChoiceRenderer interface, the two parameters to its constructor represent the displayed text and the value of the drop down options, respectively.

After I figured out how to populate the crust property of the PizzaModel, the last step was to display a confirmation page displaying all the user entered values.

Page 1 Page 2 Page 3 Page 4


Java EE 6 Development With NetBeans 7
Java EE 6 Development With NetBeans 7


Java EE 6 with GlassFish 3 Application Server
Java EE 6 with GlassFish 3 Application Server


JasperReports 3.5 For Java Developers
JasperReports 3.5 For Java Developers