Binding an unknown List of Fields

11 views
Skip to first unread message

Lew

unread,
Jul 7, 2011, 1:35:40 AM7/7/11
to GWT Pectin
Hi,

I've been playing with GWT Pectin and I think its great, however, I'm
come across a problem that I'm not sure can be implemented using
Pectin Form Models.

I have a bean that contains a Map<String,String>, and I need a have a
form that represents this map, where each Map entry has a key that is
fixed (field name), and the user can set/modify the value (field
value).

I have looked at replacing the Map with a List of "Property" beans
that has a name and value rather than a Map, but still I'm not sure
how to bind this properly to the model.

Does anyone know if there is an easy way to implement this? Or do the
fields need to be well defined?

Kind Regards,
Lew.

Andrew Pietsch

unread,
Jul 7, 2011, 6:34:39 PM7/7/11
to gwt-pecti...@googlegroups.com
Hi Lew,

First off I need to tell you that I'm no longer actively developing pectin, so help may be a little thin on the ground.

There's no direct support for maps in pectin but you should be able to bind a list of property style objects.  If your bean has a method `List<Property> getMyProperties();` you can create a list model for it using `listOfType(Property.class).boundTo("myProperties");`.  You can then bind this to anything that implements `HasValue<Collection<Property>>` (or various other interfaces).  You can use `AbstractDynamicList` as a base for implementing a simple editor for lists.  There are limitations however if your using validation on the values inside the list in that your editors (created for each item in the list) must write changes back to the underlying bean (or the validators won't see the changes).  The favorite wines widget on the first demo page uses this approach.

I had started working on a more advanced controller framework for doing this kind of thing (i.e. handling complex nested editor types) but it's sitting on my local disk.

Cheers
Andrew

Lew

unread,
Jul 7, 2011, 7:52:22 PM7/7/11
to GWT Pectin
Thanks Andrew, I had just figured out that was the approach to take.
Reply all
Reply to author
Forward
0 new messages