Monday, April 24, 2017

Re: GWT Editor with Custom Composites

Thanks Thomas, that was really helpful.

I was able to get it working using generics.

Here is a sample code if anyone else is interested (here Input is a Composite encapsulating an input element):

public class InputEditor<T>
extends Input
implements LeafValueEditor<T> {

public InputEditor(String label, InputSize size, InputType type) {
super(label, size, type);

private T value;

public T getValue() {
String theTextValue = getText();

Object theGenericValue = theTextValue;

if (value instanceof Integer) {
= Integer.parseInt(theTextValue);
} else if (value instanceof Float) {
= Float.parseFloat(theTextValue);

this.value = (T) theGenericValue;

return this.value;

public void setValue(T value) {
this.value = value;

String theTextValue = value == null ? "" : value.toString();


And simply use it (along with editor driver) like:

@UiField InputEditor<String> name;
@UiField InputEditor<Float> area;

All works well now, only word of caution: the SDM cache and the generated code sometimes would make it appear that the editor implementation doesn't flush correctly.
A mvn clean/sdm cache clean resolves this issue.


On Friday, April 21, 2017 at 5:41:38 AM UTC-4, Thomas Broyer wrote:

On Wednesday, April 19, 2017 at 8:19:52 PM UTC+2, harshyadav wrote:

I am trying to use the GWT editor framework to support data binding in my application. While implementing it I ran into a few issues and have a couple of questions regarding the same:

1) Some of these components don't use*

  rather they use*

 For e.g. InputElement as opposed to TextBox. Is it possible to use editor framework with dom elements?

There are several ways.
Either your "composite editor" implements ValueAwareEditor; in setValue extracts values from object properties and put them into the elements, on flush() do the reverse.
@Override public void setValue(MyObj value) {
  this.value = value;
@Override public void flush() {
Or use "child" editors for each element, implement a LeafValueEditor that delegates to the element in setValue/getValue.
final LeafValueEditor<String> myInputElementEditor = new LeafValueEditor<String>() {
  @Override public String getValue() { return myInputElement.getValue(); }
  @Override public void setValue(String value) { myInputElement.setValue(value); }

2) Is it possible to bind POJO's with different field types (int, float, String, etc.) to a single Composite implementing IsEditor?
For e.g. if there is an Input composite (wrapping TextBox), is it possible to use the same composite for POJO fields of different types int, float, etc. ?

public class Test
implements Serializable {

private Integer id;

private String name;

private float area;

Here name and area are of different type. Is it possible to bind these to the same widget implementing Editor (without editor I would just parse the values to and from String to their respective types before saving the data)?

The editor would have to have a generic type parameter (class MyEditor<T> implements LeafValueEditor<T>) and a way to convert the value it receives to/from String (e.g. passing converters to the constructor?)
Have a look at how ValueBox works.

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment