1

We user Wicket 6 and usually are fine with POJO objects and PropertyModel to access model attributes. Now instead of a POJO I want to use a Map, how can I do that?

Instead of

form.add(new TextField<String>("fieldName", new PropertyModel<String>(pojo, "fieldName")));

I want to use something like

form.add(new TextField<String>("fieldName", new MapModel<String>(map, "field.name")));

Is there any Wicket class to do that?

Artem
  • 7,275
  • 15
  • 57
  • 97
  • Isn't that what you want: http://ci.apache.org/projects/wicket/apidocs/6.0.x/org/apache/wicket/model/util/MapModel.html ? – Robert Niestroj Mar 16 '15 at 22:15
  • That'd expose a Mode which is a map itself. I need a model which represents just one value from the map. – Artem Mar 16 '15 at 22:35

1 Answers1

2

I think the following should do the job:

form.add(new TextField<String>("fieldName", new PropertyModel<String>(map, "keyName")));
martin-g
  • 17,243
  • 2
  • 23
  • 35
  • 3
    Although this isn't documented very clearly but `PropertyModel` (or rather, the underlying `PropertyResolver` does work with maps as you'd expect it to be. It also recognizes `length` or `size` of an array: `new PropertyModel( new String[5], "size" ).getObject() == 5`. – biziclop Mar 16 '15 at 23:12