Binding Driver To A List

38 views
Skip to first unread message

paran...@gmail.com

unread,
Jan 6, 2013, 6:58:36 PM1/6/13
to google-we...@googlegroups.com
Hello all,

first of all I'm sorry if I sound incompetent but the truth is I'm fairly new to GWT. So here's what I want to do: I have a database with different itemtypes (Product, User, Country, etc...).
I want to make a GWT application that edits these item types. For that purpose I have created a dto called EntityDto which contains a list of SectionDto, which in itself contains a list of PropertyDto. So the PropertyDto is a representation of each of the item's properties (Product.code for instance). The PropertyDto has the following signature:

public class PropertyDto implements Serializable {

  private String id;
  private String value;

  /* getters/setters */
....
}

So I have managed to display a form with TextField for the Entity's properties and their values. Now I want to submit the changed values and persist them in the database. As I was reading on the internet this is achieved using a combination of a Driver and Editor. My problem is that I don't have a real POJO to use any of the existing drivers. All I want is to map the field with id code, for instance, to the String in EntityDto.PropertyDto.value (for whichever PropertyDto has the same id).

Is there any solution to this? How would you create a form that is not backed by a bean but instead by a dynamic map or a list for instance?

Thank you for you help.

Thomas Broyer

unread,
Jan 6, 2013, 8:08:54 PM1/6/13
to google-we...@googlegroups.com
In any case, you'll have to do it manually.
If you need to use the Editor framework, and/or your scenario is complex enough to make it worth it, then you can use a ValueAwareEditor<SectionDto>: in setValue you loop over the PropertyDto-s and push their values to the corresponding text box, and in flush() you do the reverse (from text box to PropertyDto).

paran...@gmail.com

unread,
Jan 7, 2013, 2:39:40 AM1/7/13
to google-we...@googlegroups.com
Hi Thomas,

yes that sounds like exactly what I need. What I don't really understand is:
------

you loop over the PropertyDto-s and push their values to the corresponding text box
------
how do I gain access to the text-boxes? Do you have any example I can refer to?

Many Thanks

Thomas Broyer

unread,
Jan 7, 2013, 4:11:44 AM1/7/13
to google-we...@googlegroups.com


On Monday, January 7, 2013 8:39:40 AM UTC+1, paran...@gmail.com wrote:
Hi Thomas,

yes that sounds like exactly what I need. What I don't really understand is:
------
you loop over the PropertyDto-s and push their values to the corresponding text box
------
how do I gain access to the text-boxes?

They're fields in your editor.
 
Do you have any example I can refer to?

Something like:

public class SectionDtoEditor extends Composite implements ValueAwareEditor<SectionDto> {

   private SectionDto value;

   @Editor.Ignore TextBox foo;
   @Editor.Ignore TextBox bar;

   …

   @Override
   public void setValue(SectionDto value) {
      this.value = value;
      foo.setValue(getPropertyDtoValue(value, "foo");
      bar.setValue(getPropertyDtoValue(value, "bar"));
   }

   @Override
   public void flush() {
      setPropertyDtoValue(value, "foo", foo.getValue());
      setPropertyDtoValue(value, "bar", bar.getValue());
   }

   …
}

where getPropertyDtoValue extracts the value from the PropertyDto whose id is the one given as argument, and setPropertyDtoValue does the reverse.

Petar Tahchiev

unread,
Jan 7, 2013, 10:50:10 AM1/7/13
to google-we...@googlegroups.com
It works great now.

Thanks

2013/1/7 Thomas Broyer <t.br...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/8slsqTGEa_EJ.
>
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.



--
Regards, Petar!
Karlovo, Bulgaria.
---
Public PGP Key at:
https://keyserver1.pgp.com/vkd/DownloadKey.event?keyid=0x19658550C3110611
Key Fingerprint: A369 A7EE 61BC 93A3 CDFF 55A5 1965 8550 C311 0611
Reply all
Reply to author
Forward
0 new messages