Hello,
I'm using Wicket 7.
I have this simple use case where I need to have a dropdownchoice, where to
display some values, but the model should retain other values.
I have done the following, however, the model always retains null.

So my dropdownchoice should display Code1 and Code2 but save in the model
the values C1 or C2. Instead it always saves null.


==HTML==
<form wicket:id="testForm">
<table class="contenidoform"  cellpadding=1 cellspacing=0 border="0"
width="100%">
<tr>
<th>Name:</th>
<th colspan="3">
<input wicket:id="txtName" size="80"/>
</th>
</tr>
<tr>
<td>Code:</td>
<td>
<select style="width: 50%;" wicket:id="code">
<option>[Code]</option>
</select>
</td>
                               <td></td>
</tr>
<tr>
<td align="left">&nbsp;</td>
<td align="left">
<div style="padding-left: 0%;display: inline;" />
<a><input type="image" src="images/Save.gif" class="submit" name="btnSave"
value="OK" /></a>
</td>
                              <td></td>
</tr>
</table>
</form>

==JAVA==
public TestPage(IModel<TestBean> model) {
super(model);

TestForm tst = new TestForm("testForm", model);
tst.setOutputMarkupId(true);
add(tst);

}

class TestForm extends Form<TestBean> {
/**
*
*/
private static final long serialVersionUID = 1L;

public TestForm(String id, IModel<TestBean> model) {
super(id, model);

TextField<String> txtName = new TextField<String>("txtName", new
PropertyModel<String>(getModelObject(), "name"));
add(txtName);
txtName.setOutputMarkupId(true);
//choice
List<String> lst = new ArrayList<String>();
lst.add("C1");
lst.add("C2");


ChoiceRenderer<String> renderer = new ChoiceRenderer<String>("code") {

private static final long serialVersionUID = 8875819661197521211L;

@Override
public Object getDisplayValue(String arg0) {
return (arg0.equals("C1") ? "Code1" : "Code2");
}

@Override
public String getIdValue(String arg0, int arg1) {
return arg0;
}

@Override
public String getObject(String paramString, IModel<? extends List<? extends
String>> paramIModel) {
// TODO Auto-generated method stub
return null;
}

};
DropDownChoice<String> code = new DropDownChoice<String>("code", lst,
renderer);
code.setOutputMarkupId(true);
code.setModel(new PropertyModel<String>(getModelObject(), "code"));
add(code);
}

@Override
protected void onSubmit() {

logger.info("OnSubmit");
System.out.println("Code=" + getModelObject().getCode());

}
}

==Bean for the MODEL==
public class TestBean implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
private String code;
private Integer id;
public TestBean(String name, String code, Integer id) {
this.name = name;
this.code = code;
this.id = id;
}
public TestBean()
{
this.name = "";
this.code = "";
this.id =  null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}

}

Reply via email to