JAXB + GWT

1,096 views
Skip to first unread message

Kyle Anderson

unread,
Sep 3, 2011, 2:21:52 PM9/3/11
to Google Web Toolkit
I have an XML Schema defined in XSD format. Basically, there are a
whole lot of objects with attributes associated with them. The
attributes have various types (strings, enumerated types, integers).
The restrictions on these attributes are all defined in the XSD
format. I would like to create an "editor" in GWT which allows the
user to edit a file in XSD format. The editor should be able to
create a form using the XSD. For example, if there is an enumerated
type attribute, the editor should create a drop down menu.

I experimented with JAXB to generate the java bean classes from the
XSD format. The problem with this is that you cannot do reflection in
GWT, so there's no great way to view the attributes of the class in
order to create the editor window.

I imagine people have done similar things before.

Thanks!!
Kyle

Deepak Singh

unread,
Sep 3, 2011, 2:48:52 PM9/3/11
to google-we...@googlegroups.com
you need to use JAXB on the server side, not on the client side. There you can use reflection. Parse your XML and set to POJOs and get back to client.



--
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.


J.Ganesan

unread,
Sep 5, 2011, 7:55:46 AM9/5/11
to Google Web Toolkit
Have a look at http://code.google.com/p/gwt-ent/. This library will
enable you to build UI using reflection.

I have found manually restructuring JAXB output *.java files to be
very profitable. For instance, many of the classes and datatypes can
be more simply represented as enums. Also, have a look at
xmlbeans.apache.org. It may well give you a simpler output in the
context of you application.

J.Ganesan
www.DataStoreGwt.com

Alexandre Dupriez

unread,
Sep 14, 2011, 5:44:40 PM9/14/11
to Google Web Toolkit
Hello Kyle,

I faced a close issue before when I had to generate XML from JAXB-
generated beans. If JAXB-generated beans can be used on GWT client
side and converted in Javascript without concern, not are the JAXB
(un)marshallers for those beans. Unfortunately, there is not, as far
as I know, a possible straight translation of these (un)marshallers
into Javascript. GWT does not enable reflection; some frameworks
propose to work around it but I hardly think they can help to
implement an efficient JAXB translation.

Why not make the server do the job and push/pull data through RPC
calls ?

Alexandre.

Sanjiv Jivan

unread,
Sep 15, 2011, 12:10:42 AM9/15/11
to google-we...@googlegroups.com
If you're okay with using Smart GWT, it has inbuilt support for this. Have a look at this sample :


Sanjiv

Ahmet Dakoglu

unread,
Sep 15, 2011, 2:29:15 AM9/15/11
to google-we...@googlegroups.com
Hello Alexandre, "server do the job and push/pull data through RPC calls" is exactly what i do in my project.I o not use smartgwt datasource concept but only widgets.
--
Ahmet DAKOĞLU

Ahmet Dakoglu

unread,
Sep 15, 2011, 2:43:38 AM9/15/11
to google-we...@googlegroups.com
Sanjiv it may be a noob question but i manually convert my beans to listgridrecord in pojo classes and wrote my own methods for listgrid operations now tow i want to give a try to xsd datasource.The thing i do not know is, where i should put my xsd files in project hiearchy? , do i need to create every xsd in a specific folder, or how can i make datasource to use the xsd returning from gwt to server in server package of gwt?
--
Ahmet DAKOĞLU

Maiku

unread,
Sep 15, 2011, 11:23:09 AM9/15/11
to Google Web Toolkit
Hi,

If you are not totally tied to JAXB you may want to check out JIBX. I
was successfully using the beans that it creates on both Server side
and Client side. The way it marshals is by injecting information into
the bytecode and this seems to allow GWT to still recognize the source
of the beans as being the same as the compiled server object.

I have since refactored to use RequestFactory so that this entire
issue is moot but if you cannot then I highly recommend JIBX.

- Mike

J.Ganesan

unread,
Sep 16, 2011, 8:19:28 AM9/16/11
to Google Web Toolkit
Mike,

Will there be any issue in putting the JIBX generated *.java files in
shared package ? If not, JIBX has a huge advantage. I tried to put the
*.java files from JAXB in shared package and I encountered a number
of compilation problems.

J.Ganesan
www.DataStoreGwt.com

Deepak Singh

unread,
Sep 16, 2011, 11:08:05 AM9/16/11
to google-we...@googlegroups.com
No. There is no issue in putting JIBX *.java files in shared package. I use it in shared package without any issue.
Make sure you r using JIBX 1.2.3

Deepak


Maiku

unread,
Sep 16, 2011, 11:17:35 AM9/16/11
to Google Web Toolkit
There shouldn't be any problems. In my case, I had my JIBX stuff in a
separate project that got included into my webapp so I had to provide
a *.gwt.xml file in it's base folder and do an include in my main
*.gwt.xml file but other than that everything "just worked".

I was working with RPC methods, passing my XML domain objects back and
forth and converting them to XML on the server side without any gwt
related problems.

Now I should note that I had a little it of trouble with JIBX itself
in terms of converting enums to XML but that isn't related to GWT and
a benefit of JIBX is you can modify your java beans to your heart's
content (as long as your mapping files reflect what needs to be
converted) and I was able to solve any problems that way.

Another thing to mention is that JIBX has relatively little in terms
of validation in order to keep its conversion process light. But since
it produces beans you could, in theory, use a jsr 303 implementation
to do the validation annotations there (a bit of duplication from the
XML schema but can't be helped at the moment).

Harald Pehl

unread,
Sep 16, 2011, 3:07:22 PM9/16/11
to google-we...@googlegroups.com
Hi, 

I'm planning to add JAXB support to Piriti. Piriti is an XML / JSON mapper for GWT. Currently XML mapping is implemented using custom annotations. Regarding JAXB support I'm in the early design phase (see first link). So it might take some time until a first implementation is ready. But the goal is to re-use the basic JAXB annotations to (de)serialize POJOs on the cient side. This will enable you to have the same model on the server and client and use XML or JSON for the communication.

- Harald

Jirka Kr.

unread,
Sep 17, 2011, 1:51:30 PM9/17/11
to Google Web Toolkit
Thanks for JIBX, it seems interesting and they have maven plugin as
well.
Reply all
Reply to author
Forward
0 new messages