Announcement

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

    Simple way to bind a form to a XML format ?

    Hi,

    I'm trying to bind a simple form to a XML file so that it produces the request and the response automatically using a RestDataSource. I've been reading several posts about overwriting transformRequest() and transformResponse() and also the extensive documentation about SmartClient data binding.

    So far it's clear how to bind the data this way to work with tables and trees (and that's used in the examples) but a simple form isn't so easy for me. It's always sending the form fields as params.

    I'm setting the request and response to XML:

    setDataFormat( DSDataFormat.XML );
    setDataProtocol( DSProtocol.POSTXML );

    Do you know if is there something as simple as:

    nameField.setValueXPath("/name");
    addressField.setValueXPath("/address");

    So that it generates a xml like the following:

    <response>
    <status>ok</status>
    <data>
    <name>A Name</name>
    <address>An address</address>
    </data>
    </response>

    Does it need to be more complicated or am I missing anything ?

    Thanks in advance,
    Juan

    #2
    Bind form to a xml format

    Maybe I do not understand your problem, but shouldn't you bind your form to datasource ? (using OperationBinding for changing default protocol)
    Code:
    	         OperationBinding fetchOB = new OperationBinding();
    		 fetchOB.setOperationType(DSOperationType.FETCH);
    		 fetchOB.setDataProtocol(DSProtocol.POSTXML);
    		 OperationBinding updateOB = new OperationBinding();
    		 updateOB.setOperationType(DSOperationType.UPDATE);
    		 updateOB.setDataProtocol(DSProtocol.POSTXML);
    		 OperationBinding addOB = new OperationBinding();
    		 addOB.setOperationType(DSOperationType.ADD);
    		 addOB.setDataProtocol(DSProtocol.POSTXML);
    and then

    Code:
    myform.setDataSource(yourDS);

    when you call myform.savedata() it should contact with the server side by xml

    Comment


      #3
      lazinskip is correct. On the further question of trying to form an XML document by reversing the XPaths, there's no built-in support for this (and XPaths aren't generally fully reversible) but you can add some code in transformRequest that rearranges the data (possibly using your valueXPath declarations) so that SmartClient will serialize it as you want. Just put the data for a the subelement in a subobject.

      Note that if you have a WSDL service this whole process becomes much more automated.

      Comment


        #4
        Solved

        @lazinskip

        Thank you. You nailed it: that's just what I was looking for.

        @Isomorphic

        Thanks. One problem I've is that the docs are for Javascript (not that it's so hard, but if you never use it you must try to understand the idea, the language and how it translates to Java). Anyway the documentation is really great.

        Comment

        Working...
        X