GWT SimpleBeanEditorDriver - generate editor class

316 views
Skip to first unread message

Raivis Vasilevskis

unread,
Jan 19, 2012, 12:33:40 AM1/19/12
to Google Web Toolkit
Hello all!

I am building quite huge web application using GXT. I need to make
couple of hundreds windows with editable fields. What I want is to
make generator that would generate Editor UI according to DataModel in
runtime. But I can't see how this can be done as Editor field names
has to match DataModel field names (@Path annotation can be used as
well). Either way knowing this it is not possible to generate fields
based on DataModel field list in runtime. The Editor class has to be
built at compile time. Is there a way I could generate editor fields
in runtime?

-sowdri-

unread,
Jan 19, 2012, 4:40:32 AM1/19/12
to google-we...@googlegroups.com
This is possible! But you have to write a GWT Generator for to achieve that. For example: 

class Customer {
 // field1 .. field10;
}

// This still has to be written, to semantically determine what type of widget you are planning to use in your editor

interface CustomerView implements XXMarkerInterface {
  TextBox field1;
  Label field2; ... 
  ...
  <SomeWidgetType> field10;
}

// while creating the widget, instead of using the new operator, just use
CustomerView view = GWT.create(CustomerView.class);

// in the GWT.xml, you specify if type is XXMarkerInterface, invoke the generator you have written. 

In the generator implementation, you can read the interface and generate the implementation required for that!

Hope this helps!

Raivis Vasilevskis

unread,
Jan 19, 2012, 5:11:14 AM1/19/12
to Google Web Toolkit
First of all, thank you for the answer

> // This still has to be written, to semantically determine what type of
> widget you are planning to use in your editor
>
> interface CustomerView implements XXMarkerInterface {
>   TextBox field1;
>   Label field2; ...
>   ...
>   <SomeWidgetType> field10;
>
> }

If I understand you right, this par still has to be written for every
view I will create. I have literally hundreds if not thousands of
them. All the data models are generated, so I don't have to worry
about them. I want to write a generator, that would generate editors
fields according to given data model in runtime. If I still have to
write those interfaces manually, that does not differ from writing
editor classes manually. That's still the boilerplate hardcoding.
Correct me if I didn't understand you correct.

Thomas Broyer

unread,
Jan 19, 2012, 11:22:00 AM1/19/12
to google-we...@googlegroups.com


On Thursday, January 19, 2012 11:11:14 AM UTC+1, Raivis Vasilevskis wrote:
First of all, thank you for the answer

> // This still has to be written, to semantically determine what type of
> widget you are planning to use in your editor
>
> interface CustomerView implements XXMarkerInterface {
>   TextBox field1;
>   Label field2; ...
>   ...
>   <SomeWidgetType> field10;
>
> }

If I understand you right, this par still has to be written for every
view I will create. I have literally hundreds if not thousands of
them. All the data models are generated, so I don't have to worry
about them. I want to write a generator, that would generate editors
fields according to given data model in runtime.

Unless you generate some kind of "schema" and then dynamically build your UI from that schema, it'll never be "at runtime" (and as you said, the Editor framework also works at compile-time, just like almost everything in GWT)
 
If I still have to
write those interfaces manually, that does not differ from writing
editor classes manually. That's still the boilerplate hardcoding.
Correct me if I didn't understand you correct.

Let's simplify things:

interface /* or class, it doesn't really matter */ Customer extends XXXMarkerInterface<Customer> {
}

Now you have a "link" from CustomerView to Customer (by mean of the generic type argument), that you can inspect at compile-time to generate the concrete implementation for CustomerView (something like "hey, Customer as a property "name" of type String, let's create a TextBox for it; and let's use a DateBox for the "birthDate" property; and finally, generate the EditorDriver interface and the code that GWT.create()s it")

That'd work, but everything would be automated when you "GWT Compile" your app.

If I were you, I'd rather write a generator outside GWT; one that loads the model classes (compiled, from the classpath, it's the easiest way) and generate Java code out of it (same as above), and then use that generated code from your GWT project. Difference: you can tweak the generated code before "GWT Compiling" your app.
Simply use Java reflection to inspect your model classes, and FileWriter-s to generate your code.
We use this approach to generate our RequestFactory proxies out of our model classes; works very-well.

-sowdri-

unread,
Jan 20, 2012, 12:34:05 AM1/20/12
to google-we...@googlegroups.com
>> If I were you, I'd rather write a generator outside GWT;

Thanks Thomas for pointing this out! Now I could understand that Generators are not the only way of using reflection in GWT.


Sathya prakash

unread,
Sep 24, 2014, 2:06:32 PM9/24/14
to google-we...@googlegroups.com


On Friday, January 20, 2012 12:34:05 AM UTC-5, -sowdri- wrote:
>> If I were you, I'd rather write a generator outside GWT;

Thanks Thomas for pointing this out! Now I could understand that Generators are not the only way of using reflection in GWT.

Hi, 

I'm having  a similar requirement, were you able to implement this ? ,    Regards
Reply all
Reply to author
Forward
0 new messages