Announcement

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

    Problem using AdvancedCriteria and velocity $criteria variable

    It seems that when I have a single criteria the $criteria substitution variable works but when I have multiple criteria via use of AdvancedCriteria it does not. In the first instance I am issuing the following DSRequest.
    Code:
    === 2010-04-14 19:00:36,881 [l0-2] DEBUG RPCManager - Request #1 (DSRequest) payload: {
        criteria:{
            FileGroupSuffix:"_F002"
        },
        operationConfig:{
            dataSource:"PoHeader",
            operationType:"fetch",
            textMatchStyle:"exact"
        },
        startRow:0,
        endRow:75,
        componentId:"isc_OID_222",
        appID:"builtinApplication",
        operation:"PoHeader_fetch",
        oldValues:{
            FileGroupSuffix:"_F002"
        }
    }
    The custom SQL in my ds.xml looks, in part, like this.
    Code:
    FROM ippohdr#if($rawValue.criteria.FileGroupSuffix)$rawValue.criteria.FileGroupSuffix#end 
    	join POItem on HONO=IONO   
    where $defaultWhereClause
    The resulting SELECT statement looks like this. So far so good.
    Code:
    FROM ippohdr_F002 join POItem on HONO=IONO where ('1'='1')
    In the second scenario my DSRequest looks like this.
    Code:
    === 2010-04-14 19:01:38,841 [l0-3] DEBUG RPCManager - Request #1 (DSRequest) payload: {
        criteria:{
            _constructor:"AdvancedCriteria",
            operator:"and",
            criteria:[
                {
                    _constructor:"AdvancedCriteria",
                    fieldName:"IONO",
                    operator:"equals",
                    value:"0HOMETEX03"
                },
                {
                    _constructor:"AdvancedCriteria",
                    fieldName:"FileGroupSuffix",
                    operator:"equals",
                    value:"_F002"
                }
            ]
        },
        operationConfig:{
            dataSource:"PoItem",
            operationType:"fetch",
            textMatchStyle:"exact"
        },
        startRow:0,
        endRow:75,
        componentId:"isc_OID_225",
        appID:"builtinApplication",
        operation:"PoItem_fetch",
        oldValues:{
            _constructor:"AdvancedCriteria",
            operator:"and",
            criteria:[
                {
                    _constructor:"AdvancedCriteria",
                    fieldName:"IONO",
                    operator:"equals",
                    value:"0HOMETEX03"
                },
                {
                    _constructor:"AdvancedCriteria",
                    fieldName:"FileGroupSuffix",
                    operator:"equals",
                    value:"_F002"
                }
            ]
        }
    }
    My custom SQL looks almost identical to the first.
    Code:
    from ippoitm#if($rawValue.criteria.FileGroupSuffix)$rawValue.criteria.FileGroupSuffix#end
    WHERE $defaultWhereClause
    But the resulting SELECT looks like this.
    Code:
    from ippoitm WHERE ((IONO = '0HOMETEX03' AND IONO IS NOT NULL))
    Why isn't $rawValue.criteria.FileGroupSuffix being replaced by the FileGroupSuffix criteria? Is there an alternative syntax I need to use with Advanced criteria?

    #2
    $criteria actually represents the criteria object as it arrives on the server, so you would need something like $criteria.criteria[1].value.

    We might add future support for a $flattenedCriteria or similar that would extract field/value pairs from a (potentially nested) AdvancedCriteria.

    Comment


      #3
      Should mention, you could add such a thing yourself (you can add things to the Velocity context via the DSRequest).

      Comment


        #4
        Can you tell me exactly how to add things to the Velocity context? I've tried DSRequest.setAttribute() and DSRequest.setEvalVars() and neither seem to add anything to what the server gets.

        Comment


          #5
          OK. I think I get it now.
          Code:
          String poNumber = event.getRecord().getAttribute("HONO");
          AdvancedCriteria ionoCriteria = new AdvancedCriteria("IONO", OperatorId.EQUALS);
          ionoCriteria.setAttribute("value", poNumber);
          DSRequest myReq = new DSRequest();
          Map extras = new HashMap();
          extras.put("FileGroupSuffix", fileGroupSuffix);
          myReq.setParams(extras);
          getPoItemGrid().fetchData(ionoCriteria, null, myReq);
          poStack.expandSection("poItemSection");
          And in the custom SQL ...
          Code:
          #if($httpParameters.FileGroupSuffix)$rawValue.httpParameters.FileGroupSuffix#end

          Comment


            #6
            That works too, but what we actually meant was dsRequest.addToTemplateContext().

            Comment


              #7
              addToTemplateContext() is only available on the server side com.isomorphic.datasource.DSRequest class, not on com.smartgwt.client.data.DSRequest. Is there a reason for that?

              Comment


                #8
                Velocity and it's dependencies can't be loaded client side, so you couldn't do anything but basic data types, and it would be dangerous to use because the data being passed doesn't go through validation and most people would not immediately realize it needed to be validated (unlike http params). What would be the point of having it on the client when the client also has dsRequest.data, params and many other clear ways of getting data to the server already?

                Comment

                Working...
                X