Announcement

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

    DSRequest & DSResponse

    I use SmartGWT 2.4 LGPL.
    I read The Smart GWT Quick Start Guide, in fact i use the restdatasource to communicate among client and server. We send a request to the server and it make an response xml, then the client read the response xml with an absolute url. But there is a problem. The xml response is shared by multiple clients, what can you do?
    We wrote the code manually without DSRequest & DSResponse, because i can't understand about these methods. In more, I could not find an example of server-side. Is there anybody who can explain how the dsrequest and dsresponse?

    I understood this:
    client --> dsrequest obj --> server
    server --> dsresponse obj --> client
    ok?

    Dsrequest & Dsresponse question:
    how do you create the response in xml format? Is there any method?

    #2
    is there anyone!?

    Comment


      #3
      I am sorry, I use a listGrid and a tileGrid with all the 4 binding operations (add, remove, update, fetch).

      Comment


        #4
        I can not believe that there is no one to explain this argument.

        Comment


          #5
          Maybe I misunderstood your request... but I suppose most of forum users consider you request too generic (can I say too messy?).
          BTW here you are some of my understanding: SmartGWT LGPL comes only with client-side components, hence if you want server-side components directly from SmartGWT authors you should buy a more complete version, and Isomorphic guys will be very happy ;-).
          Nonetheless if you prefer to use only the LGPL version the easiest way to make it communicate with a server that matches your needs is using RestDataSource.
          I quote here the relevant documentation for Client-side Data Integration
          For new applications, the RestDataSource provides a complete XML or JSON-based protocol that supports all of the features of SmartClient's databinding layer (data paging, server-side validation errors, automatic cache synchronization, etc). To use the RestDataSource, simply write server code that can parse RestDataSource requests and produce the required responses; example requests and responses are provided.
          That said, it should be clear that creating a response in xml format - or whatever you want - is only a server matter.
          For instance, I use REST services at the server side on my grails apps (see JAX-RS), hence my server-side code somewhat resembles this snippet
          Code:
          @Path('/api/myds)
          class TestResource {
              @GET
              @Produces('application/json')
              Response list(@QueryParam('query') String sQuery) {
                  def builder = new JSONBuilder()
                  //somewhat loads somedata that will be used by the appropriate writer to produce a json response
                  Response.ok(new RestDataSourceResponse (status: 0, data: somedata)).build()
              }  
          }
          but - as you can easily see - the request parsing and response generation depend on the technology you choose at server-side. You only have to be compliant with the request and response format documented for RestDataSource.
          So dsrequest and dsrequest are some sort of transfer objects, available at client side for customization purposes.
          Honestly I'm not sure to understand what you meant saying
          The xml response is shared by multiple clients
          Hope that helps.

          Cheers
          Davide
          Last edited by d.cavestro; 6 Sep 2011, 06:20.

          Comment


            #6
            You can use jdom library to create xml responses or xstream if you want work with java objects which will be serialized to xml format. As d.cavestro said your xml response has to be in RestDataSource protocol. Below example of creating xml response with jdom:
            Code:
            		Document responseDoc = new Document();
            		Element rootElresp = new Element("response");
            		responseDoc.setRootElement(rootElresp);
            		Element elStatus = new Element("status");
            		elStatus.setText("0");
            		Element elStartRow = new Element("startRow");
            		elStartRow.setText(String.valueOf(paczkaUzytkownik.getStartRow()));
            		Element elEndRow = new Element("endRow");
            		elEndRow.setText(String.valueOf(paczkaUzytkownik.getEndRow()));
            		Element elTotalRows= new Element("totalRows");
            		elTotalRows.setText(String.valueOf(paczkaUzytkownik.getTotalRows()));
            		
            		Element elData = new Element("data");
            		rootElresp.addContent(elStatus);
            		rootElresp.addContent(elStartRow);
            		rootElresp.addContent(elEndRow);
            		rootElresp.addContent(elTotalRows);
            		rootElresp.addContent(elData);
            		for (Uzytkownik uzytkownik: paczkaUzytkownik.getDane()){
            			Element elRecord = new Element("record");
            			elData.addContent(elRecord);
            			Element elUserId = new Element("userId");
            			elUserId.setText(String.valueOf(uzytkownik.getUserId()));
            			elRecord.addContent(elUserId);
            			Element elUserLogin = new Element("userLogin");
            			elUserLogin.setText(uzytkownik.getUserLogin());
            			elRecord.addContent(elUserLogin);
            			Element elUserHaslo = new Element("userHaslo");
            			elUserHaslo.setText(uzytkownik.getUserHaslo());
            			elRecord.addContent(elUserHaslo);
            			Element elAdmin = new Element("admin");
            			elAdmin.setText(uzytkownik.getAdmin());
            			elRecord.addContent(elAdmin);
            
            		}
            		return responseDoc;

            Comment


              #7
              Thanks for the answers, luckily someone there.

              DSResponse: ok, I understand how to create, but I did not know where you save the answer? We saved her from a server-side ".xml" file which is then read by the client due to an absolute address. However I have not figured out how to manage the response. Could you explain better?
              Last edited by medju; 7 Sep 2011, 07:11.

              Comment


                #8
                is there anyone?

                Comment


                  #9
                  is there anyone?

                  Comment


                    #10
                    is there anyone?

                    Comment


                      #11
                      I my case when request comes with "add" operation, I have to parse the request, do some logic via hibernate based on request fields. Persisted object (or objects list) is then used to create response returned to the server. You have to note that request for "add" operation doesn't contain unique id for new record which is required for datasource. I am getting this id from database after record has been persisted.
                      I don't know why you try to save answer to server side xml. If this mean that every record added in yoor application has its own file (or maybe all records are stored in one big xml file) ?

                      Comment

                      Working...
                      X