Announcement

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

    Multiline XML response

    Hi, i have a little problem :
    I have a DataSource Associate to a form that i dont display (i reuse the response ):

    Code:
    Criteria c = new Criteria();
    		c.addCriteria( "uid", record.getAttribute( "uid" ) );
    		c.addCriteria( "folderURL", record.getAttribute( "folderURL" ) );
    		Temp.fetchData( c, new DSCallback()
    		{
    			
    			public void execute( DSResponse response, Object rawData, DSRequest request )
    			{
                              ...................................................................................
                            }

    In the rest side, i return to client the following xml :

    Code:
    <response>
      <status>0</status>
      <startRow>0</startRow>
      <endRow>1</endRow>
      <totalRows>1</totalRows>
      <data>
        <records>
          <message>
            <subject></subject>
            <sentDate>2009-02-27 12:22:08.0 CET</sentDate>
            <size>3662</size>
            <from>fayssal161466979@free.fr</from>
            <recipientTo>
              <Address>glev4retbe12345706@gmail.com</Address>
              <Name>Ben</Name>
             <Address>bob@bob.bob</Address>
              <Name>Bob</Name>
            </recipientTo>
            <uid>474</uid>
            <folderURL>gvfdg</folderURL>
            <summary>dfsg</summary>
            <content>dsfg</content>
            <seen>true</seen>
            <gotAttachment>dfsg</gotAttachment>
          </message>
        </records>
      </data>
    </response>

    On client size i try to get recipientTo,but without any success :
    Code:
    ListGridRecord[] li = response.getData();
    li[0].getAttributeAsObject( "recipientTo" );
    That return me Objet object.

    Any suggestion to get this data?
    Regards Ben

    #2
    In this case getAttributeAsObject should return you a JavaScriptObject that contains the data in the recipientTo subelement.

    You could instead "flatten" the data model using DataSourceField.valueXPath.

    Comment


      #3
      i try this:

      Code:
      	
      recipientTo = new DataSourceEnumField( "recipientTo", "recipientTo" );
      recipientTo.setValueXPath( "//response/data/records/message/recipientTo" );
      When i call record.getAttribute("recipientTo"), that return to me
      "\n "

      and this :
      Code:
      recipientTo = new DataSourceTextField( "recipientTo", "recipientTo" );
      recipientTo.setValueXPath( "//response/data/records/message/recipientTo/Address" );
      that return me only the first Address:
      glev4retbe12345706@gmail.com

      Any help ?

      Comment


        #4
        if anyone can help me to solve my problem it would be nice
        thanks everybody

        Comment


          #5
          Originally posted by BeN01
          Code:
          <response>
            <startRow>0</startRow>
            <endRow>1</endRow>
            <totalRows>1</totalRows>
          Isn't it wrong? From smartclient documentation:
          DSResponse.totalRows: Total number of rows available from the server that match the current filter criteria, when using paged result fetching.

          endRow: End row of returned server results, when using paged result fetching.
          Note that startRow *and* endRow are zero-based - the first record is row zero.
          In your case:
          Code:
          endRow - startRow + 1 == 2 > totalRows

          Comment


            #6
            valueXPath is relative to the record. You want just recipientTo/address.

            You also have an extra tag, get rid of <records>.

            Comment


              #7
              I want all the recipientTo/Address, i can have more than 1 value and i dont know how to get them ...

              If i the valueXPath to recipientTo/Address or recipientTo/Name, my result is only the value of the first recipientTo.

              Comment


                #8
                any help ?

                Comment


                  #9
                  Using valueXPath will mean each record gets on recipientTo/Address. If there are multiple records each will have a Name and Address.

                  If this doesn't help, start over and post a much clearer explanation of the data you're working with and how exactly it needs to be displayed.

                  Comment


                    #10
                    Each record have one recipientTo that contains a lot of Adress and Name :
                    Code:
                    <response>
                      <status>0</status>
                      <startRow>0</startRow>
                      <endRow>1</endRow>
                      <totalRows>1</totalRows>
                      <data>
                        <records>
                          <message>
                            <subject></subject>
                            <sentDate>2009-02-27 12:22:08.0 CET</sentDate>
                            <size>3662</size>
                            <from>fayssal161466979@free.fr</from>
                            <recipientTo>
                              <Address>glev4retbe12345706@gmail.com</Address>
                              <Name>Ben</Name>
                               <Address>glev4retbe12345706@gmail.com</Address>
                              <Name>Ben</Name>
                              <Address>glev4retbe12345706@gmail.com</Address>
                              <Name>Ben</Name>
                             <Address>bob@bob.bob</Address>
                              <Name>Bob</Name>
                            </recipientTo>
                            <uid>474</uid>
                            <folderURL>gvfdg</folderURL>
                            <summary>dfsg</summary>
                            <content>dsfg</content>
                            <seen>true</seen>
                            <gotAttachment>dfsg</gotAttachment>
                          </message>
                        </records>
                      </data>
                    </response>
                    I just want to retrieve all the Name and Adress in a List or in a String[] ...

                    Comment


                      #11
                      I had a similar issue. I solved it this way..

                      The code to get it in a String[] :
                      Code:
                      ListGridRecord[] li = response.getData();
                      JavaScriptObject jso = li[0].getAttributeAsJavaScriptObject( "recipientTo" );
                      JsArray arr = jso.cast();
                      
                      String[] addressArr = new String[arr.length()];
                      for(int i=0;i<arr.length();i++)
                      {
                      	addressArr[i] = JSOHelper.getAttribute(arr.get(i),"Address");
                      }
                      if u print addressArr.. u shud get all the values in there.

                      Hope this helps.

                      Cheers,
                      Hetal
                      Last edited by hgaglani; 6 Apr 2009, 07:29.

                      Comment


                        #12
                        Originally posted by Isomorphic
                        Using valueXPath will mean each record gets on recipientTo/Address. If there are multiple records each will have a Name and Address.
                        What we are looking for is multiple elements in each record and not multiple records so basically in terms of XML.. another complexType element within a complexType element.

                        Like Ben mentioned and like I had mentioned in my post, the Xpath recipientTo/Address just returns the first Address value from the whole object in case there are multiple address elements in each record.

                        What solution I have posted works.. but I wanted to know if there is a direct solution to work with the Datasource (or XPath) for the sample XML shown to retrieve the multiple address elements from the recipientTo node.

                        Thanks,
                        Hetal
                        Last edited by hgaglani; 6 Apr 2009, 07:46.

                        Comment


                          #13
                          Hi Hetal,

                          As previously mentioned, your data has an extra <records> element that you need to get rid of if you are using RestDataSource.

                          A properly formed XPath will return multiple values if the XPath is correct. If you think there's a SmartGWT problem here, the best thing to do is post a standalone test case so we can more quickly take a look at it and either correct your usage and identify a bug.

                          Comment


                            #14
                            then please explain me how ...
                            The only thing i can obtain setting the valueXpath is "\n "
                            I do it using getAttribute("recipientTo")

                            the value Xpath i set :
                            Code:
                            recipientTo = new DataSourceTextField( "recipientTo", "recipientTo" );
                            recipientTo.setValueXPath( "//response/data/records/message/recipientTo" );
                            Pls help me

                            (if i use a JavaScriptObject i throw an exception)

                            thanks!

                            Comment


                              #15
                              any suggestions ?

                              Comment

                              Working...
                              X