Generating GWT widgets based on an XML template

84 views
Skip to first unread message

Arshad

unread,
May 25, 2011, 2:12:17 AM5/25/11
to Google Web Toolkit
Hi all,

I'm pretty new to GWT, so please bear... Coming from a Struts
background, GWT concepts takes a lot of getting used to :)

I have a requirement of defining a user interface in a custom XML
template, process it to generate a technology independent generic
component tree, and use this tree to generate various different user
interfaces (e.g. Swing, GWT, JSF, etc...). To get this going, I make
use of reflection to transfer values from the generic component to the
Swing/GWT/JSF component.

I'm in the process of developing the GWT part, and feel like theirs
two ways of approaching this:
1. Do only the XML processing in the server side. The client makes an
RPC call and retrieves the generic component tree in to the client
side in order to generate the GWT widgets. This doesn't seem to be an
option since GWT doesn't support reflection on the client side.

2. Do both the XML processing and the GWT widget generation on the
server side. The client makes an RPC call and retrieves the generated
GWT widgets. This also doesn't seem to be possible... may be because
it the widgets are not serializable?

I would really appreciate any input regarding this. Is there anyway I
can generate the GWT widgets on the server side and retrieve it from
the client side? Or is there any other way I can approach this
problem?

Thanks in advance,
Arshad

Gabriel

unread,
May 25, 2011, 11:14:20 AM5/25/11
to Google Web Toolkit
Hi,

I can think of two options to implement what you want:
1) On the server side generate DTOs that represent the UI structure
and on the client side read them and build the UI accordingly.
2) Generate pure HTML on the server and use it as the value of an HTML
widget.

The choice depends on what exactly you need from the client side. You
should minimize the use of widgets as much as possible, and use them
only if you need to capture events. Otherwise it is recommended to use
HTML.

Gabriel

Arshad Nadheem

unread,
May 25, 2011, 12:26:36 PM5/25/11
to google-we...@googlegroups.com
Thanks for the response Gabriel... it's the 1st option that I'm
looking for. Generating HTML is not an option for me, since each of my
widgets need to be self-contained components. So, the 1st option is
the way to go for me.

But this is where my problem starts... I'd love to use reflection to
populate the widgets. I.e for each getters in my DTO, I try to invoke
the corresponding setter in the widget (if exists). E.g.: If my
ButtonDTO has a getHeight(), I'd check if the Button widget has a
setHeight(). If so, I'd call setHeight() of the Button widget with the
value of buttonDTO.getHeight().

The easiest way to do this is through reflection, so that I won't have
to do the above manually for each property. Of course some values
cannot be set in this manner... that has to be dealt in the normal
way.

So, if I follow the approach that you mentioned as option 1, I won't
be able to use reflection, right? Any workarounds?

Thanks again,
Arshad

> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> 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.
>
>

Gabriel

unread,
May 25, 2011, 2:08:12 PM5/25/11
to Google Web Toolkit
Indeed you can't use reflection, but note that a vast majority of the
widget properties are actually style (as in CSS) properties, so you
can take advantage of it. I'm thinking in this direction: in your DTO
have a Map<String,String> where the keys are style properties and the
values are the style values, and on the client side iterate over the
map and for each entry call
Widget.getElement().getStyle().setProperty(key, value). You can do the
same with attributes, this time call
Widget.getElement().setAttribute(key, value). And the last thing you
have to deal with is innerText (or innerHTML). So you can write a
generic mechanism that handles styles, attributes and innerText and
that should cover everything.

Arshad Nadheem

unread,
May 26, 2011, 12:17:20 AM5/26/11
to google-we...@googlegroups.com
That's awesome... I never tough in the lines of setting CSS into widgets... Thanks a lot!
So this means that I can have my reflection thing going on the server side - to populate the Map with key/value pairs of the fields in the DTO..!

Cheers,
Arshad

BST

unread,
Jan 13, 2012, 1:28:42 AM1/13/12
to google-we...@googlegroups.com
I have been looking for something like this and this seems to be a good strategy.@Arshad Would be great if you let me know if this was successful.

My query is how did/would you push the values from the generated UI to a database ? The DTO is representing the UI, and how to capture the values from the generated widgets ?

Pandy .k

unread,
Jan 13, 2012, 2:09:51 AM1/13/12
to google-we...@googlegroups.com
May be this link will help you.......


after that any query means contact my mail id..



by,
pandy.k
DEAS Technology Private Limited, Chennai.

Reply all
Reply to author
Forward
0 new messages