Reputation: 689
I create a table in html page.
There are two columns in that table.
wicket:id = “key_column”
wicket:id = “value_column”
I'm going to display map data (key and value).
How I solved this is ..
TreeMap<String, String> map = new Treemap<~>();
map = getDataFormProvider();
List<String> keyList = new ArrayList<~>();
for (String key : map.keySet()) {
keyList.add(key);
}
DataView<String> dataView = new DataView<~>("displayPanel", new ListDataProvider(keyList)) {
@Override
protected void populateItem(Item item) {
String key = (String) item.getModelObject();
item.add(new Label("key_column", key));
item.add(new Label("value_column", map.get(key)));
}
};
Is there any possibility to display map
as a table directly without getting keyList
like above?
Upvotes: 1
Views: 1445
Reputation: 2341
Not really. But you can reduce the code passing the list of entries:
DataView<Entry<String, String>> dataView = new DataView<~>("displayPanel", new ListDataProvider(new ArrayList<Entry<String, String>(map.entrySet())) {
@Override
protected void populateItem(Item item) {
Entry<String, String> entry = item.getModelObject();
item.add(new Label("key_column", entry.getKey()));
item.add(new Label("value_column", entry.getValue()));
}
});
Upvotes: 2