uweschaefer / wicket-modelfactory

API to create Wicket PropertyModels in a typesafe and refactoring-safe way
http://www.wicketeer.org/wicket-modelfactory/getting_started.html
Other
3 stars 1 forks source link

Getting Model object from a ValueMap #4

Closed bluecosmo closed 9 years ago

bluecosmo commented 9 years ago

Hello,

first of all, great library. My question is how can i connect a ValueMap with wicketeer?

In normal wicket it is:

new PropertyModel<String>(captchaModel.getObject().getProperties(), "captchaInput")

where 'captchaModel.getObject().getProperties()' is a ValueMap.

Cheers

uweschaefer commented 9 years ago

Thanks for the kind words.

ModelFactory is a tool to get Type-Safety into PropertyModel in the first place, so using it for type "Properties" does not bring any advantage, as it looses the type-info already.

Two things strike me on your code snippet above:

  1. the propertymodel seems to be wrong in a sense that it has a static reference to captchaModel.getObject().getProperties()

normally, you'd want to be able to resolve that at request processing time, like pm = new PropertyModel(captchaModel, "properties"); and then maybe use a AbstractReadOnlyModel to pick "captchaInput" from the pm model.

  1. i suggest you don't use any kind of Map for model data, as you loose all the type info and make your code prone to errors.

Better use a proper Bean like: class CaptchaInput{ String userProvidedCaptcha; // getters/setters }

then you could use ModelFactory like

PropertyModel inputModel = model(from(myCaptchInputBean).getUserProvidedCaptcha())

If you cannot do that, because a thrid party Component gives you nothing but a Map, as mentioned above, i suggest you implement an AbstractReadonlyModel.

Take this with a grain of salt as it is pulled from the little code you posted without knowing enough about your Context. Still, i guess the Wicket-User mailinglist is your friend when it comes to proper usage of PropertyModels.

Have fun with Wicket.