Using Enumerations as a Model Object in Wicket

To use the Enum class in the PropertyModel, you can write:

new PropertyModel(MyObject, "MyEnumClass"); 

Now this only works if MyEnumClass defined in the MyObject class.

How can I use the standalone Enum class in the model?

Edit: Specify:

 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 is that changing the switch does not change the model on RadioGroup .

+6
source share
2 answers

I just found a problem: I used AjaxEventBehavior on my RadioGroup instead of AjaxFormChoiceComponentUpdatingBehavior .

This fixed the model update issue for my code in question.

+2
source

I used the following without problems for my NMR type component NMRType DropDownChoice:

 IModel<NMRType> default = Model.of(NMRType.HNMR); List<NMRType> choices = Arrays.asList(NMRType.values()); DropDownChoice<NMRType> nmrDDC = new DropDownChoice<NMRType>("nmrType", default, choices); 

Just note: be careful not to write to your Enum models. Wicket uses reflection, which can cause a few surprises if you do.

+2
source

Source: https://habr.com/ru/post/887693/


All Articles