Announcement

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

    How can we use synchronous Datasource operations?

    Hi All,

    I am new to use/learn SmartGWT and stuck with a problem regarding Datasource. I have a Datasource fetch operation and the value I get from DSCallBack of this is processed in subsequent logic. But since the Datasource operations are asynchronous, am sometimes left with blank/null values.

    Let me know if I am doing something wrong or if there is a way to do Synchronous calls to Datasource.

    Code:
    	private String setRoleField(String attribute) {
    		Criteria rolefetchCriteria = new Criteria();
    		rolefetchCriteria.addCriteria("searchFlag", 1);
    		rolefetchCriteria.addCriteria("User_ID", attribute);
    
    		requestProperties =new DSRequest();		
    		requestProperties.setOperationId("outletRoleFetch");
    		
    		DataSource.get("recently_accessed_module").fetchData(rolefetchCriteria, new DSCallback() 
    		{
    			@Override
    			public void execute(DSResponse dsResponse, Object data,
    					DSRequest dsRequest) {
    					
    				
    				Record[] record = dsResponse.getData();	
    				outletRole = "";
    				for(Record singlerecord: record)
    					outletRole += "<font class='overview-subtitle'>"+singlerecord.getAttribute("OutletName")+"</font><font class='overview-time-label'>"+ singlerecord.getAttribute("Role")+"</font>";	
    
    			}
    			
    	  },requestProperties);	
    
    return outletRole;
    	}
    This code is always returning me "" empty value.

    The Smartclient version am using is -->SmartClient Version: v10.0d_2014-09-09/EVAL Deployment

    Thanks,
    Babu

    #2
    Hi vinobabu,

    clientside DSRequests are always asynchronous. So your DSCallback-approach is correct.

    Are you sure that your call returns any data? If not, your result would be correct, wouldn't it? Please check this in the Developer Console's RPC-tab. See the BuiltInDS sample for how to open the Developer Console.

    Best regards,
    Blama

    Comment


      #3
      Thanks for the reply Blama.

      Yes I get DSResponse in Dev console, but the method in which the DS operation is happening doesn't return a valid value.

      In other words, my function is returning value before the DSCallBack is received from the Datasource. I am thinking if this can be solved by making the Datasource operations Synchronous.

      I am interested to know how this issue is solved universally across SmartGWT users. If we don't have the option to make a DSRequest Synchronous, how is the situation when DSRespose is not received in few seconds and the subsequent business logic is receiving "no Data".

      Thanks and Regards,
      Babu

      Comment


        #4
        Hi Babu,

        I didn't see the return. Does this sample help?
        Generally speaking you won't get rid of the asynchronous nature of SmartGWT/GWT/AJAX, so you'll do much work in Callbacks.

        Best regards,
        Blama

        Comment


          #5
          Hi Babu,
          you can pass a callback object to your setRoleField method, which you can call when the data is available. So your setRoleField method returns void and the data is available via your callback.

          Comment


            #6
            Thanks edulid.

            This sounds like a plan. Could you please provide me a prototype of it, which will help me more.

            Thanks and Regards, Babu

            Comment

            Working...
            X