DPM
DPM

Reputation: 2030

Wicket - use map's entry values as objects in a model where I know the key for each component

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...

Upvotes: 0

Views: 1157

Answers (2)

Rob Audenaerde
Rob Audenaerde

Reputation: 20019

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.

Upvotes: 0

Alexey Mukas
Alexey Mukas

Reputation: 739

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.

Upvotes: 1

Related Questions