hi all....i got a little problem here
i want to make this into a select component :
if the label is "user" then the value would be : 0(Integer)
if the label is "administrator" then the value would be : 1(Integer)
i did that in this way :
*User.java*
private String username;
private String password
private Integer status;
......
*userForm.tml*
<tr>
<td><t:label for="statusSelect"/></td>
<td> :</td>
<td><t:select t:id="statusSelect" model="statusSelectionModel"
value="User.status" encoder="statusValueEncoder" label="Status"/></td>
</tr>
*userForm.java*
......
@Property
private User user;
......
public List<String> getStatusList() {
if(statusList==null){
statusList = new ArrayList<String>();
statusList.add("user");
statusList.add("administrator");
}
return statusList;
}
public StatusSelectionModel getStatusSelectionModel() {
return new StatusSelectionModel(getStatusList());
}
public ValueEncoder<Integer> getStatusValueEncoder(){
return new StringValueEncoder();
}
*StatusSelectionModel.java*
public class StatusSelectionModel implements SelectModel{
private List<String> statusList;
public StatusSelectionModel(List<String> formationList){
this.statusList = formationList;
}
public List<OptionGroupModel> getOptionGroups() {
return getSelectModel().getOptionGroups();
}
public List<OptionModel> getOptions() {
return getSelectModel().getOptions();
}
public void visit(SelectModelVisitor visitor) {
getSelectModel().visit(visitor);
}
public SelectModel getSelectModel() {
List<OptionModel> optionModelList = new ArrayList<OptionModel>();
for(String status: statusList) {
if(status.equals("user")){
optionModelList.add(new OptionModelImpl(status,new
Integer(0)));
}else if (status.equals("administrator")) {
optionModelList.add(new OptionModelImpl(status,new
Integer(1)));
}
}
return new SelectModelImpl(null, optionModelList);
}
}
*StringValueEncoder .java*
public class StringValueEncoder implements ValueEncoder<Integer> {
public String toClient(Integer value) {
return value.toString();
}
public Integer toValue(String value) {
// TODO Auto-generated method stub
return Integer.parseInt(value);
}
}
but i got following error when i tried to submit it :
*Failure writing parameter 'value' of component UserFormPage:statusselect:
Coercion of user to type java.lang.Integer (via String --> Long, Long -->
Integer) failed: For input string: "user"*
*
*
could somebody help me
thnx u very much
--
http://dwiardiirawan.blogspot.com
"cos everyone could be extraordinary...lighten up !"