The code below works just fine for me. Instead of using complex type as a
model object for a drop down I use an instance of IChoiceRenderer to control
what's used for an id and what's displayed as a value.
User user = ....;
setModel(new CompoundPropertyModel(user));
....
add(new DropDownChoice("usrRole", SystemRole.asStringList(), new
IChoiceRenderer() {
@Override
public String getDisplayValue(Object object) {
return Enum.valueOf(SystemRole.class,
object.toString()).getRoleName();
}
@Override
public String getIdValue(Object object, int index) {
if (index == -1) {
return SystemRole.SALESMAN.toString();
}
return SystemRole.asStringList().get(index);
}
}).setRequired(true));
The combo items are populated from Enum values:
public enum SystemRole {
SYS_ADMIN("Administrator systemu"),
SERVICEMAN("Serwisant"),
NETWORK_ADMIN("Administrator sieci"),
SALESMAN("Pracownik punktu"),
ANY("Bez roli");
private final String roleName;
SystemRole(String roleName) {
this.roleName = roleName;
}
public String getRoleName() {
return roleName;
}
private static List<String> stringList;
public static List<String> asStringList() {
if (stringList == null) {
stringList = new ArrayList<String>();
for (SystemRole sr : values()) {
stringList.add(sr.toString());
}
}
return stringList;
}
}
And this is how model object looks like:
public class User {
private Integer usrId;
private String usrLogin;
private String usrPasswrd;
private String usrEmail;
private String usrMobile;
private String usrLandline;
private String usrFirstName;
private String usrLastName;
private String usrRole;
}
Hope this helps :-)
cheers,
Marcin
--
View this message in context:
http://www.nabble.com/CompoundPropertyModel-and-Combobox-tp23733910p23741340.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]