Hi,
This example is working for me:
DropDownChoice ddc = new DropDownChoice("departments", new
Model(userDepartment) {
@Override
public UserDepartment getObject() {
return userDepartment;
}
@Override
public void setObject(Serializable object) {
if (object != null) {
userDepartment = (UserDepartment) object;
}
}
}, userDepartmentService.getAll(), new
ChoiceRenderer("department", "id"));
add(ddc.setRequired(true));
userDepartment is an object and consists of id and a department, also it is
an
instance variable in the Page/Form that i use the DropDownChoice in.
So userDepartment is pretty much like youre Region object...
userDepartmentService.getAll() => returns the list of UserDepartments to be
displayed.
Hope you can use it.
Best Regards
Cemil
On Fri, Aug 21, 2009 at 1:25 PM, Harrie Hazewinkel <[email protected]>wrote:
> HI,
>
> I am trying to make a 'simple' DropDownChoice in a form for a class called
> region,
> but when I push the submit Wicket does not understand how to convert it
> back to
> the Region class. (see below for code sample)
>
> Does anyone have a hint? Or maybe sample code?
>
> Harrie
>
>
> The Region class is basically a class that combines an id with a name.
>
> public class Region {
> private long id;
> private String name;
>
> public long getId() {
> return id;
> }
> public String getName() {
> return name;
> }
> }
>
> The drop down goes correctly with the code below. The options in the
> select box have the correct name and ids.
>
>
> public class RegionDropDownChoice extends DropDownChoice<Region> {
>
> @SpringBean
> private RegionService regionService;
>
> public RegionDropDownChoice(String id, List<Region> regionList) {
> this(id, false, regionList);
> }
>
> public RegionDropDownChoice(String id, boolean nullValid, List<Region>
> regionList) {
> super(id);
> setType(Region.class);
> setNullValid(nullValid);
> setChoiceRenderer(new ChoiceRenderer<Region>() {
> public Object getDisplayValue(Region Region) {
> return Region.getName();
> }
>
> @Override
> public String getIdValue(Region Region, int index) {
> return Region.getName();
> }
> });
> setChoices(regionList);
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>