I’d like to know something about wicket supporting models with generic. I understood the models, prop model, and prop compound model.
But what about the Model class? What happen if I do this:
Label<Person> label = new Label<Person> ( "someID", new Model<Person>() )
What will be show in that label? toString output?
Lets say I have the same in a TextField. What value it will set up in that object?
The source code of Wicket is very well documented and self-explanatory.
Labelis usinggetDefaultModelObjectAsString()fromComponentthat look like this:So here you can see that Wicket uses a
IConverterto convert the model object to aString. Looking at the implementation of the defaultConverterLocatoryou’ll see that if you haven’t registered anyIConverterfor this type of object, Wicket will use theDefaultConverterthat usesorg.apache.wicket.util.lang.Objectsstatic methods to convert the object to aString.The
TextFieldalso uses aIConverterto convert the object to aStringand from theStringto an object again. The difference is that Wicket is able to always convert an unknown class to aStringusing thetoStringmethod, but not the other way. So if you want to use aIModel<Person>with aTextFieldyou’ll need to register your ownIConverter<Person>implementation.