Announcement

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

    DSRequest Params Not Being Sent To Server After Upgrade

    Hi Isomorphic,

    After upgrading from "v10.1p_2017-08-10/Pro Deployment (built 2017-08-10)" to "v12.0p_2018-08-28/Pro Deployment (built 2018-08-28)" DSRequest parameters that we were setting are no longer being passed to the server.

    I have provided the use case below.

    The parameter, param1, is no longer available in the request on the server after upgrading, breaking some of our functionality.

    Thanks

    -----

    EntryPoint

    Code:
    package com.sandbox.client;
    
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.AutoFitWidthApproach;
    import com.smartgwt.client.types.FetchMode;
    import com.smartgwt.client.types.RecordComponentPoolingMode;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.FetchDataEvent;
    import com.smartgwt.client.widgets.events.FetchDataHandler;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class Sandbox12 implements EntryPoint {
    
        DSRequest requestProperties;
    
        @Override
        public void onModuleLoad() {
            final ListGrid list = new ListGrid();
            list.setWidth100();
            list.setHeight100();
            list.setDataSource(DataSource.get("sandbox12"));
            list.setDataFetchMode(FetchMode.PAGED);
            list.setAutoFitFieldsFillViewport(Boolean.TRUE);
            list.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
            list.setAutoFitFieldWidths(Boolean.TRUE);
            list.setCanFreezeFields(Boolean.FALSE);
            list.setCanGroupBy(Boolean.FALSE);
            list.setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE);
            list.setAlternateRecordStyles(Boolean.TRUE);
            list.setAutoFetchData(Boolean.TRUE);
            list.setShowRollOver(Boolean.FALSE);
    
            ListGridField gfld1 = new ListGridField("name");
            ListGridField gfld2 = new ListGridField("groupNames");
            ListGridField gfld3 = new ListGridField("id");
            list.setDefaultFields(gfld1, gfld2, gfld3);
    
            list.addFetchDataHandler(new FetchDataHandler() {
                @Override
                public void onFilterData(FetchDataEvent event) {
                    requestProperties = event.getRequestProperties();
                }
            });
    
            VLayout appLayout = new VLayout();
            appLayout.setWidth100();
            appLayout.setHeight100();
    
            IButton btnLoad = new IButton("Run");
            btnLoad.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Map params = requestProperties.getAttributeAsMap("params"); // or Map params = requestProperties.getParams(); in 12.0.
                    if (params == null) params = new LinkedHashMap<String, Object>();
                    params.put("param1", System.currentTimeMillis());
                    requestProperties.setParams(params);
                    list.invalidateCache();
                }
            });
    
            appLayout.setMargin(5);
            appLayout.setMembersMargin(5);
            appLayout.addMembers(btnLoad, list);
            appLayout.draw();
        }
    }
    sandbox12.ds.xml

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <DataSource xmlns:fmt="WEB-INF/" ID="sandbox12" serverType="generic">
        <fields>
            <field name="id" type="text" primaryKey="true" canEdit="false">
                <title>UUID</title>
            </field>
            <field name="name" type="text" length="255" required="true">
                <title>Name</title>
            </field>
            <field name="groupNames" type="text" multiple="true" canFilter="false" canEdit="false"> 
                <title>Group Names</title>
            </field>
        </fields>
        <serverObject lookupStyle="new" className="com.sandbox.server.Sandbox12DS"/>
    </DataSource>
    Server DS Object

    Code:
    package com.sandbox.server;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import com.isomorphic.datasource.DSRequest;
    import com.isomorphic.datasource.DSResponse;
    
    public class Sandbox12DS {
    
        public Sandbox12DS() {}
    
        public DSResponse fetch(final DSRequest req) {
            String param1 = req.getHttpServletRequest().getParameter("param1");
            // NOTE: param1 available with "v10.1p_2017-08-10/Pro Deployment (built 2017-08-10)", however, it is no longer available with "v12.0p_2018-08-28/Pro Deployment (built 2018-08-28)".
            DSResponse resp = new DSResponse();
            resp.setStartRow(req.getStartRow());
            resp.setEndRow(req.getEndRow());
            resp.setTotalRows(1000);
            resp.setData(getTestData(req.getStartRow(), req.getEndRow()));
            return resp;
        }
    
        private List<Map<String, Object>> getTestData(long startRow, long endRow) {
            List<Map<String, Object>> rList = new ArrayList<>();
    
            HashMap<String, Object> r;
            String id;
            String groupName;
            for (long i = startRow; i <= endRow; i++) {
                r = new HashMap<String, Object>();
                id = Long.toString(i);
                r.put("id", id);
                r.put("name", "Item" + id);
                groupName = "Group" + id;
                r.put("groupNames", new String[] { groupName });
                rList.add(r);
            }
    
            return rList;
        }
    }

    #2
    This isn't a valid approach. You are grabbing a property that's meant to be read-only off of a temporary request object and just happened to luck out that it was internally re-used in a previous version; the new version makes a copy of these properties to avoid cases where application code was unintentionally side-effecting the same object.

    The simplest way to do this correctly is to add your param in dataSource.transformRequest. However, from the test case, it seems like some kind of attempt to defeat caching; if so, consider rpcRequest.bypassCache, which sends an if-modified-since HTTP header to avoid cached GET requests.

    Comment


      #3
      Hi Isomorphic,

      I suspected that might be your response.

      We have moved the adding of the parameters to the request into our transformRequest implementation.

      Thanks

      Comment

      Working...
      X