0

I have a Java Map where I store data that has to be shown in a row in a table in a web application. I am using Wicket 6.

Is there a way to link Wicket Labels (which will be cells in my table) to the String version of an object in a Map knowing the key for each Label.

Should I implement my own version of IModel or is there any convenience class in the Wicket 6 libraries? As far as I can see there is none, but I could be wrong...

icrovett
  • 435
  • 7
  • 21
DPM
  • 1,960
  • 3
  • 26
  • 49

2 Answers2

1

You can implement IModel also you can implement IConverter<C>.

To use custom converter override Component#getConverter like so:

   Label lbl = new Label("lbl"){
        @Override
        public <C> IConverter<C> getConverter(Class<C> type) {
            //return converter here
        }
    };

For components like Label you can implement only convertToString method.

Alexey Mukas
  • 739
  • 5
  • 12
  • Thanks for the IConverter suggestion for the String representation. I think I will end up implementing my own map's entry kind of model as I can't seem to find a readily available class. – DPM Apr 18 '13 at 14:01
  • note: IConverter is needed if change your label say to TextField – Alexey Mukas Apr 18 '13 at 14:05
  • More info you can find in an excellent guide https://code.google.com/p/wicket-guide/ (see ch. 10.3) – Alexey Mukas Apr 18 '13 at 14:12
0

I think there is no such IModel implementation at the current moment. It is not too hard to write your own IModel<String> that takes your Map and a key in the constructor and return the String.valueOf(map.get(key)) ;)

Just make sure that either your Map is Serializable or otherwise, you should provide a LoadableDetachableModel for your map and use that.

Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121