Hey all,
Okay, I must be crazy or something, but I can’t seem to figure out how to properly databind a java.util.Map.
Some background info:
Our company uses a tree-like structure to represent connections between virtual files. Every virtual file is pointed towards by a virtual file link, this way we’re able to represent the same file (or actually the same file contents) at different locations in the tree, a bit like symlinks in linux. We use Hibernate to store objects in a database, these link objects are stored there as well.
Now for my problem:
A link object has a metadata Map. This is a simple java.util.Map<String, String> storing all kinds of interesting information about the link, such as the name, a string representation of the creation date, etc.
I would like to show the data in this Map by using a Table (seemed like the most natural representation of a Map; a two column Table). However, I can’t seem to figure out how to get Vaadin to bind it properly.
What I have tried so far is:
- Create a MetadataMap class, extending an IndexedContainer
- Use
addContainerProperty(x, String.class, null)
for x is {key:String, value:String}, thus adding two String container properties - Then fill the container by creating empty Item objects, then retrieving all the entries from the original Map and adding them as properties to the item
- Use this MetadataMap as a datasource for the Table
This setup properly shows all the Map items in the Table. However, If I want to be able to edit the values in the Value column, this will never work, as there is no “real” binding between the
Map.Entry<String, String>
objects in the Map and their representation. Now, using the Map.Entry objects as Items, then adding the properties using
i.getItemProperty(key).setValue(e.getKey());
doesn’t seem to work either.
Anyway, I must be overlooking something trivial I guess, as most people on the forum have way more difficult questions…
Thanks in advance.
Cheers, Peter
Ps. Attached are (parts of) the source used, in case my explanation is a bit too mind boggling
11495.java (952 Bytes)
11496.java (889 Bytes)