Hi,
I've been trying to get something to work for a few days now, but i cannot seem to get the desired result by any means i try. I've got a datasource with a field configured like this:
The valueXPath attribute works fine if you only want to have it retrieve a single value from a property. Like mentioned in the API of DataSourceField:
But what if you want to return a list of ID's instead of a single ID value? I only want the participants ID's to be returned instead of a entire object graph converted to JSON. As you can see in the code above i tried the JXPath expression to select each ID, but this only gives me back the first ID in the Set returned.
Is there any way to get a list of ID's returned based on the ds.xml configuration? Or do i need to resort to the IToJson interface on each JavaBean where i want a Collection of elements to only return the id's of the elements inside it?
Thanks in advance.
I've been trying to get something to work for a few days now, but i cannot seem to get the desired result by any means i try. I've got a datasource with a field configured like this:
Code:
<DataSource ID="Communication" inheritsFrom="...." DataSourceVersion="1" xmlFromConfig="true" beanClassName="..." dropExtraFields="true" titleField="subject" serverType="generic" serverConstructor="..."> <fields> <field name="subject" type="text" length="50" canHide="false" required="true" width="*" colSpan="2" startRow="true"> </field> <field name="category" valueXPath="category/id" type="Category" editorType="select" optionDataSource="Category" javaClass="..." valueField="id" displayField="localizedLabel" width="*"> </field> <field name="channel" valueXPath="channel/id" type="Channel" editorType="select" optionDataSource="Channel" javaClass="..." valueField="id" displayField="localizedLabel" width="*"> </field> <field name="content" type="text" editorType="textArea" width="*" colSpan="2" startRow="true" detail="true"> </field> <field name="participants" valueXPath="participants//id" multiple="true" type="AbstractCommunicableObject" editorType="select" width="*" colSpan="2" startRow="true" optionDataSource="AbstractCommunicableObject" javaClass="..." detail="true" hidden="false" ignore="false"> </field> </fields> </DataSource>
Using valueXPath with the Smart GWT server
If you're using the Smart GWT server to return data via the DSResponse object (or indirectly doing so using DataSource DMI), the valueXPath you specify on the DataSource fields will be applied to the data you return via the JXPath library.
If you are returning Java Beans as your DSResponse data, normally each dataSource field receives the value of the same-named Java Bean property, that is, a field "zipCode" is populated by looking for "getZipCode()" on the objects passed as DSResponse data. You can use valueXPath to retrieve properties from subobjects, so long as a chain of getter methods exists that corresponds to the valueXPath. For example, a valueXPath of "address/zipCode" expects to call "getAddress()" on the bean(s) passed to DSResponse.setData(), followed by "getZipCode()" on whatever object "getAddress()" returns.
When you are saving data, the inbound DSRequest values, available as a Java Map, will use just dataSource field names as Map keys, not the valueXPath used to derive them. However, to achieve bidirectional valueXPath binding, you can use the server-side method dataSource.setProperties() to use the valueXPath when setting properties on your server object model. When applied as a setter, an XPath like "address/zipCode" attempts "getAddress()" followed by "setZipCode()" on the returned object. JXPath also has some ability to auto-create intervening objects if they are missing, such as auto-creating an "address" subobject when applying "address/zipCode" as a valueXPath.
See the JXPath library documentation for complete details, including other types of server object models supported, such as server-side XML.
If you're using the Smart GWT server to return data via the DSResponse object (or indirectly doing so using DataSource DMI), the valueXPath you specify on the DataSource fields will be applied to the data you return via the JXPath library.
If you are returning Java Beans as your DSResponse data, normally each dataSource field receives the value of the same-named Java Bean property, that is, a field "zipCode" is populated by looking for "getZipCode()" on the objects passed as DSResponse data. You can use valueXPath to retrieve properties from subobjects, so long as a chain of getter methods exists that corresponds to the valueXPath. For example, a valueXPath of "address/zipCode" expects to call "getAddress()" on the bean(s) passed to DSResponse.setData(), followed by "getZipCode()" on whatever object "getAddress()" returns.
When you are saving data, the inbound DSRequest values, available as a Java Map, will use just dataSource field names as Map keys, not the valueXPath used to derive them. However, to achieve bidirectional valueXPath binding, you can use the server-side method dataSource.setProperties() to use the valueXPath when setting properties on your server object model. When applied as a setter, an XPath like "address/zipCode" attempts "getAddress()" followed by "setZipCode()" on the returned object. JXPath also has some ability to auto-create intervening objects if they are missing, such as auto-creating an "address" subobject when applying "address/zipCode" as a valueXPath.
See the JXPath library documentation for complete details, including other types of server object models supported, such as server-side XML.
Is there any way to get a list of ID's returned based on the ds.xml configuration? Or do i need to resort to the IToJson interface on each JavaBean where i want a Collection of elements to only return the id's of the elements inside it?
Thanks in advance.
Comment