简体   繁体   中英

Binding Set to form with ListItems in Wicket

So I work with Apache Wicket and I have the Model class with the attributes:

private String name;
private Set<Details> details;

where Details class is

private String detailsName;
private DetailsEnum detailsEnum;

and DetailsEnum is enum { SOME, MORE, MOST }. I have problem with a Set of Details. There is the ListView but it works with a List, not a Set. I need to have the form like this:

name:[ examplemodelname ]

detailsName : [here dropDownChoice with this enum]

detailsName : [here dropDownChoice with this enum]

detailsName : [here dropDownChoice with this enum]

But I don't know how to bind Set in a proper way.

Do you want create 3 dropDownChoice, but in your model you have set of Details. Can't be sure that in set exist 3 objects.

I would change Model:

private String name;
private DetailsEnum detail1;
private DetailsEnum detail2;
private DetailsEnum detail3;

And in your form with CompundPropertyModel of your model:

form.add(new DropDownChoice<>("detail1"), Arrays.asList(DetailsEnum.SOME, DetailsEnum.MORE, DetailsEnum.MOST), new Arrays.asList(DetailsEnum.values()));
form.add(new DropDownChoice<>("detail2"), Arrays.asList(DetailsEnum.SOME, DetailsEnum.MORE, DetailsEnum.MOST), new Arrays.asList(DetailsEnum.values()));
form.add(new DropDownChoice<>("detail3"), Arrays.asList(DetailsEnum.SOME, DetailsEnum.MORE, DetailsEnum.MOST), new Arrays.asList(DetailsEnum.values()));

You also can rewrite the displayed value, except of new Arrays.asList(DetailsEnum.values()) write new EnumChoiceRenderer<DetailsEnum>(this) and define something like this in property file:

DetailsEnum.SOME=Some
DetailsEnum.MORE=More
DetailsEnum.MOST=Most

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM