Binding Java object to XML Datasource GWT
I need a little help on a java problem:
In one sentence: I want to present the user with the structure of a java object, ie each field values (a toString () will do), and the possibility to browse complex types (lists, maps, etc..).
roughly, the view "Variables" of Eclipse
I have some technical limitations:
JAVA objects (retrieved from a repository running on a jdk1.4)
rendering done in a GUI GWT (jdk1.6)
my items are quite complex and their structure is not known in advance
I begin just my thoughts and at first sight, I am tempted to approach the problem from this angle:
1) GWT likes the datasources in XML. So far I see GWT manipulate an XML describing the object that I must show (form name = attribute name, value = toString () attribute)
2) I must then find a java lib allowing me to generate XML on the fly from a java object passed as parameter, by introspection attributes (or possibly use getters).
Any idea?
Re: Binding Java object to XML Datasource GWT
xstream, but it only works on server side
Re: Binding Java object to XML Datasource GWT
The fact that it runs on the server side does not worry, the very opposite:
The manipulation will require a call server side to retrieve the full Java object, so as to make as much as the Transco java-> xml is done server side.
Thank you in any case.
Re: Binding Java object to XML Datasource GWT
XStream is not bad, I also used JAXB 2 (included in J2EE) and it works very well too.
Re: Binding Java object to XML Datasource GWT
OK, thank you, I started watching the side of XStream:
Not bad actually, and it can easily highlight the directory structure of a java object as XML.
Here, I encountered two limitations of GWT:
1) XML input grid is not an XML "standard" (with n levels) nested XML but a "flat" for each subject with a foreign key to its parent object.
Code:
<List>
−
<employee>
<EmployeeId>4</EmployeeId>
<ReportsTo>1</ReportsTo>
<Name>Charles Madigan</Name>
<Job>Chief Operating Officer</Job>
<Phone>x10962</Phone>
<Email>cmadigan@server.com</Email>
<OrgUnit>Management</OrgUnit>
<Salary>26200.00</Salary>
<Gender>male</Gender>
<MaritalStatus>married</MaritalStatus>
<EmployeeType>full time</EmployeeType>
<EmployeeStatus>active</EmployeeStatus>
</employee>
−
<employee>
<EmployeeId>192</EmployeeId>
<ReportsTo>4</ReportsTo>
<Name>Ralph Brogan</Name>
<Job>Mgr Software Client Supp</Job>
<Phone>x32524</Phone>
<Email>rbrogan@server.com</Email>
<OrgUnit>Management</OrgUnit>
<Salary>13700.00</Salary>
<Gender>male</Gender>
<MaritalStatus>married</MaritalStatus>
<EmployeeType>full time</EmployeeType>
<EmployeeStatus>active</EmployeeStatus>
</employee>
−
<employee>
<EmployeeId>295</EmployeeId>
<ReportsTo>192</ReportsTo>
<Name>Bhushan Sambhus</Name>
<Job>Line Worker</Job>
<Phone>x12125</Phone>
<Email>bsambhus@server.com</Email>
<OrgUnit>Management</OrgUnit>
<Salary>8300.00</Salary>
<Gender>female</Gender>
<MaritalStatus>married</MaritalStatus>
<EmployeeType>part time</EmployeeType>
<EmployeeStatus>active</EmployeeStatus>
</employee>
</List>
2) GWT expects that the fields are defined explicitly in order to render ... This is not my case, because the generated XML by XStream uses as a tag attribute names ...
In short, I must find a way to convert the XML into an XML XStream "GWT compliant" ... and it is not won