Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Help with positioning DSRequest custom node

    In the context of a RestDataSource I managed to generate a request like this by overriding RestDataSource.transformRequest:

    Code:
    <request>
      <data>
         <isc_OID_21>
           [B]<customTag>blah</customTag>[/B]
           <field1>foo</field1>
           <field2>bar</field2>
         </isc_OID_21>
       </data>
       <oldValues></oldValues>
       <dataSource>isc_OID_21</dataSource>
       <operationType>add</operationType>
       <componentId>isc_OID_53</componentId>
    </request>
    where my custom node <customTag> goes inside the <data> tag.

    But can anyone tell me how to generate a request like the one below??

    Code:
    <request>
      [B]<customTag>blah</customTag>[/B]
      <data>
         <isc_OID_21>       
           <field1>foo</field1>
           <field2>bar</field2>
         </isc_OID_21>
       </data>
       <oldValues></oldValues>
       <dataSource>isc_OID_21</dataSource>
       <operationType>add</operationType>
       <componentId>isc_OID_53</componentId>
    </request>
    where my custom node <customTag> goes under the <request> tag at the same level as the <data> tag.
    I have tried with DSRequest.setAttribute(String, String) but that didn't have any impact on the request XML.

    Thanks,
    Luc

    #2
    Ok I found a solution and I produced a DSRequest XML as follows:

    Code:
    <request>
      [B]<fooTag>barValue</fooTag>[/B]
      <data>
         <isc_OID_21>       
           ...
         </isc_OID_21>
       </data>
       <oldValues></oldValues>
       <dataSource>isc_OID_21</dataSource>
       <operationType>add</operationType>
       <componentId>isc_OID_53</componentId>
       ...
    </request>
    Here is how I did it:

    Code:
    import com.google.gwt.xml.client.Document;
    import com.google.gwt.xml.client.Element;
    import com.google.gwt.xml.client.XMLParser;
    
    // ...
    
    RestDataSource dataSource = new RestDataSource() {
    	@Override
    	protected Object transformRequest(DSRequest dsRequest) {
    		// We assume that Object is the request XML String since we have used DSDataFormat.XML 
    		String xml = (String) super.transformRequest(dsRequest);
    		
    		Document doc = XMLParser.parse(xml);
    		Element root = doc.getDocumentElement();
    		Element newElement = doc.createElement("fooTag");
    		newElement.appendChild(doc.createTextNode("barValue"));
    		root.appendChild(newElement);
    			
    		xml = doc.toString();
    		
    		return xml;
    	}
    };
    dataSource.setDataFormat(DSDataFormat.XML);
    So I used the embedded GWT XML parsing interface.

    To Isomorphic team: is there any better approach using some SmartGWT interface?
    Last edited by dindeman; 2 Aug 2010, 14:48.

    Comment

    Working...
    X