To use an Enum class in a PropertyModel you can write:
new PropertyModel(MyObject, "MyEnumClass");
Now this only works if MyEnumClass
is defined within the MyObject
-class.
How can I use a stand-alone Enum-class in a model?
Edit: I c开发者_如何学JAVAoncretize:
RadioGroup<MyEnum> rg = new RadioGroup<MyEnum>("radioGroupID", new Model<MyEnum>(MyEnum.NORMAL));
rg.add(new Radio<MyEnum>("radioNormal", new Model<MyEnum>(MyEnum.NORMAL)));
rg.add(new Radio<MyEnum>("radioSpecial", new Model<MyEnum>(MyEnum.SPECIAL)));
The problem here is that changing the radio button doesn't change the model on the RadioGroup
.
I've been using the following without a problem for my Enum "NMRType" DropDownChoice component:
IModel<NMRType> default = Model.of(NMRType.HNMR);
List<NMRType> choices = Arrays.asList(NMRType.values());
DropDownChoice<NMRType> nmrDDC =
new DropDownChoice<NMRType>("nmrType", default, choices);
Just a note: Be careful not to write to your Enum models.. Wicket uses reflection, which might throw up a few surprises if you do..
I just found the problem: I was using AjaxEventBehavior
on my RadioGroup
instead of AjaxFormChoiceComponentUpdatingBehavior
.
This fixed the model updating problem for my code in the question.
精彩评论