Announcement

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

    SWGT 4.0d - Data not transfered in DSResponse

    Since I updated to SGWT 4.0d Power (2013-02-23), the following code does not work anymore:

    Server side: manually sets data (HashMap) of the response
    Code:
    	private DSResponse getDSResponse(Box box) throws Exception{
    
            HashMap<String,String> data = new HashMap<String,String>();
            data.put("url",box.getURL());
    
            DSResponse resp = new DSResponse();  
            resp.setStatus(DSResponse.STATUS_SUCCESS);  
            resp.setData(data);
            
            return resp;
    	}
    client side is supposed to receive in the response the data set by the server but response.getData() returns an empty array of record while in 3.1 it returned the expected record containing the HashMap.
    Code:
    	                     ds.performCustomOperation(oparationId,new Record(),new DSCallback(){
    
    							public void execute(DSResponse response,Object rawData, DSRequest request) {
    								Record records[] = response.getData();
    								if (records.length>0){
    									String URL = records[0].getAttribute("url");
    									if (!(MoonDesktop.getProperty("chart.delete")).equals("false")){
    										URL += "?delete=true";
    									}
    									htmlFlow.setContentsURL(URL);
    									htmlFlow.show();
    								}
    							}
    	                     },request);

    #2
    We can't reproduce this because it isn't clear how this code should be hooked up. The fact that the method is declared private suggests that it can't ever have worked as a straight DMI call. Please show the DataSource and share the details of how this code gets invoked.

    Comment


      #3
      ok, here follows the full story:

      The client class (Chart) manages an htmlflow that is supposed to show a chart generated dynamically by another application. When refresh() is called, the class prepares the parameters to be send to the server for the chart generation, these parameters are sent along with the DSRequest. In the response the class is supposed to receive from the server the URL where the chart will be generated.

      On the server side these parameters are captured and the full chart data is generated to be sent to the other application that returns the url to access the chart. This URL is sent back to the caller (client) within the DSResponse.


      Client part (class Chart)
      Code:
      package com.nside.moon.client_desktop.charts;
      
      import java.util.HashMap;
      
      import com.nside.moon.client_desktop.MoonDesktop;
      import com.nside.moon.client_desktop.security.Secured;
      import com.nside.moon.client_desktop.views.View;
      import com.smartgwt.client.data.DSCallback;
      import com.smartgwt.client.data.DSRequest;
      import com.smartgwt.client.data.DSResponse;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.Record;
      import com.smartgwt.client.types.ContentsType;
      import com.smartgwt.client.types.Overflow;
      import com.smartgwt.client.widgets.Canvas;
      import com.smartgwt.client.widgets.HTMLFlow;
      
      public abstract class Chart extends Canvas implements Secured{
      
      	private View view;
      	private String dsName;
      	private String oparationId;
      	private boolean isParent;
      
      	private HTMLFlow htmlFlow;
      
      	public Chart(View view,String groupTitle,String dsName,String operationId,boolean isParent,int extraSpace) {
      		super();
      
      		this.setExtraSpace(extraSpace);
      		
      		this.view = view;
              this.dsName = dsName;
              this.oparationId = operationId;
              this.isParent = isParent;
      
              if (view!=null) view.addSecuredCanvas(this);		
      
              if (groupTitle!=null){
          		setIsGroup(true);  
                  setGroupTitle(groupTitle);
              }
              
              htmlFlow = new HTMLFlow();  
              htmlFlow.setContentsType(ContentsType.PAGE);
              htmlFlow.setOverflow(Overflow.HIDDEN);
              htmlFlow.setWidth("99%");
              htmlFlow.setHeight("99%");
              addChild(htmlFlow);
              
      	}
      
      	public View getView() {
      		return view;
      	}
      	
      	public HTMLFlow getHTMLFlow(){
      		return htmlFlow;
      	}
      	
      	public void refresh(){
      
      		htmlFlow.setContentsURL(null);
      		htmlFlow.hide();
      
      		if (MoonDesktop.getShowGraphics()){
      
      			if (dsName!=null){
      	        	
      	        	DataSource ds = DataSource.getDataSource(dsName);
      	        	
      	        	if (ds!=null){
      	        		
      	        		final int recordId = view.getScreen().getSelectedId(isParent);
      	        		
      	        		if (recordId>0){
      	        			
      	            		DSRequest request = new DSRequest();
      	            		HashMap<String,String> params = new HashMap<String,String>();
      	            		
      	            		params.put("id",String.valueOf(recordId));
      	            		params.put("width",String.valueOf(getClientWidth()));
      	            		params.put("height",String.valueOf(getClientHeight()));
      	            		params.put("horizontal",String.valueOf(true));
      
      	            		addCustomParameters(params);
      	            		
      	            		request.setParams(params);
      	                    
      	                     ds.performCustomOperation(oparationId,new Record(),new DSCallback(){
      
      							public void execute(DSResponse response,Object rawData, DSRequest request) {
      								Record records[] = response.getData();
      								if (records.length>0){
      									String URL = records[0].getAttribute("url");
      									if (!(MoonDesktop.getProperty("chart.delete")).equals("false")){
      										URL += "?delete=true";
      									}
      									htmlFlow.setContentsURL(URL);
      									htmlFlow.show();
      								}
      							}
      	                     },request);
      	        		}
      	        	}
      	        }
      
      			
      		}
      
      		
      	}
      	
      	public void setSecurity(boolean canView,boolean canUpdate,boolean canNew,boolean canDelete){
      	}
      	
      	public abstract void addCustomParameters(HashMap<String,String> params);
      	
      	public abstract int getClientWidth();
      	public abstract int getClientHeight();
      	
      	
      
      }
      Server part (dmi which is public, the private method that I showed previously is not directly the dmi).
      Code:
      package com.nside.moon.server.dmi;
      
      import java.util.HashMap;
      
      import com.isomorphic.datasource.DSRequest;
      import com.isomorphic.datasource.DSResponse;
      import com.nside.moon.server.charts.Box;
      import com.nside.moon.server.charts.BoxDashboardCash;
      import com.nside.moon.server.charts.BoxDashboardInvestments;
      import com.nside.moon.server.charts.BoxDashboardOrders;
      import com.nside.moon.server.charts.BoxDashboardProspects;
      import com.nside.moon.server.charts.BoxDashboardSFH;
      import com.nside.moon.server.charts.BoxDashboardSFM;
      import com.nside.moon.server.charts.BoxDashboardSFY;
      import com.nside.moon.server.charts.BoxDashboardSalesFunnel;
      import com.nside.moon.server.charts.BoxDashboardWarnings;
      import com.nside.moon.server.charts.BoxInvestmentStatus;
      import com.nside.moon.server.charts.BoxMoonitorProjects;
      import com.nside.moon.server.charts.BoxMoonitorProspects;
      import com.nside.moon.server.charts.BoxMoonitorSFM;
      import com.nside.moon.server.charts.BoxOrderStatus;
      import com.nside.moon.server.charts.BoxPersonSalary;
      import com.nside.moon.server.charts.BoxProspectStatus;
      
      public class MakeChartDMI {
      	
      	public DSResponse getURLChartDashboardCash(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardCash(dsRequest.getHttpServletRequest()));
      	}
      	
      	public DSResponse getURLChartDashboardSFH(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardSFH(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartDashboardSFY(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardSFY(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartDashboardSFM(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardSFM(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartDashboardSalesFunnel(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardSalesFunnel(dsRequest.getHttpServletRequest()));
      	}
      
      	
      	public DSResponse getURLChartDashboardWarnings(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardWarnings(dsRequest.getHttpServletRequest()));
      	}
      	
      	public DSResponse getURLChartDashboardProspects(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardProspects(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartDashboardOrders(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardOrders(dsRequest.getHttpServletRequest()));
      	}
      	
      	public DSResponse getURLChartDashboardInvestments(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxDashboardInvestments(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartProspectStatus(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxProspectStatus(dsRequest.getHttpServletRequest()));
      	}
      	
      	public DSResponse getURLChartOrderStatus(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxOrderStatus(dsRequest.getHttpServletRequest()));
      	}
      	
      	public DSResponse getURLChartInvestmentStatus(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxInvestmentStatus(dsRequest.getHttpServletRequest()));
      	}
      	
      	public DSResponse getURLChartPersonSalary(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxPersonSalary(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartMoonitorSFM(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxMoonitorSFM(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartMoonitorProspects(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxMoonitorProspects(dsRequest.getHttpServletRequest()));
      	}
      
      	public DSResponse getURLChartMoonitorProjects(DSRequest dsRequest) throws Exception {
      		return getDSResponse(new BoxMoonitorProjects(dsRequest.getHttpServletRequest()));
      	}
      
      	private DSResponse getDSResponse(Box box) throws Exception{
      
              HashMap<String,String> data = new HashMap<String,String>();
              data.put("url",box.getURL());
      
              DSResponse resp = new DSResponse();  
              resp.setStatus(DSResponse.STATUS_SUCCESS);  
              resp.setData(data);
              
              return resp;
      	}
      	
      }
      The Chart class can be linked to many ds, here is one of them, the bound operation is one of them, the problem appears on each.
      The .ds.xml
      Code:
      <DataSource
          ID="ui_form_moonitor"
      	serverType="sql"
      	tableName="ui_form_moonitor"
      >
          <fields>
              <field name="id"						title="Id"					type="sequence"		primaryKey="true"	hidden="true" 	foreignKey="ui_form_moonitor_.id"/>
              <field name="id_currency"				title="¤"					type="integer"		required="true"		foreignKey="ui_list_currencies.id"/>
       	    <field includeFrom="ui_form_moonitor_.sneak"								/>
       	    <field includeFrom="ui_form_moonitor_.id_person_owners"						/>
       	    <field includeFrom="ui_form_moonitor_._is_started"							/>
       	    <field includeFrom="ui_form_moonitor_._is_final"							/>
       	    <field includeFrom="ui_form_moonitor_.currencySymbol"						/>
          </fields>
         	<operationBindings>
              <binding operationType="custom" operationId="getURLSFM" serverMethod="getURLChartMoonitorSFM">
                  <serverObject lookupStyle="new" className="com.nside.moon.server.dmi.MakeChartDMI"/>
              </binding>
              <binding operationType="custom" operationId="getURLProspects" serverMethod="getURLChartMoonitorProspects">
                  <serverObject lookupStyle="new" className="com.nside.moon.server.dmi.MakeChartDMI"/>
              </binding>
              <binding operationType="custom" operationId="getURLProjects" serverMethod="getURLChartMoonitorProjects">
                  <serverObject lookupStyle="new" className="com.nside.moon.server.dmi.MakeChartDMI"/>
              </binding>
          </operationBindings>         
      </DataSource>
      The problem is that even if MakeChartDMI/getDSResponse(Box box)/box.getURL() works fine and returns a proper URL, which is in turn sent to the DSResponse, Record records[] = response.getData(); in the callback of ds.performCustomOperation Chart/refresh() returns an empty record list, while in 3.1p one record is returned with the HashMap containing the expected url

      Hope this helps, Ben.

      Comment


        #4
        This is a regression in the way the client-side getData() method handles a single object where it was expecting an array. It should be fixed in today's (3/1) 4.0d nightly.

        Comment


          #5
          Working fine now, thanks!

          Comment

          Working...
          X