Announcement

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

    Passing criteria value to ds.xml

    Hello Isomorphic,

    I have a problem in passing the criteria value to ds.xml. Please find the
    details below:

    SmartGWT Power 2.4 - (SC_SNAPSHOT-2011-01-05/PowerEdition Deployment 2011-01-05)
    Browser: Any

    snippet from ds.xml:

    <operationBinding
    operationType = "fetch"
    <tableClause> T_APP_MOD_MASTER </tableClause>
    <whereClause><![CDATA[
    ...
    T_APP_MOD_MASTER.APP_ID(+) = $criteria.APP_ID AND
    T_APP_MOD_MASTER.MOD_ID(+) = $criteria.MOD_ID AND
    ($defaultWhereClause)
    ]]>
    </whereClause>
    </operationBinding>

    DataSource appModMasterDS = DataSource.get("T_APP_MODULE_MASTER");
    AdvancedCriteria ac1 = new AdvancedCriteria("APP_ID", OperatorId.EQUALS, "1");
    AdvancedCriteria ac2 = new AdvancedCriteria("MOD_ID", OperatorId.EQUALS, "9");
    AdvancedCriteria acArray[] = {ac1, ac2};

    AdvancedCriteria c1 = new AdvancedCriteria(OperatorId.AND, acArray);
    AdvancedCriteria c2 = getAdditionalCriteria();

    AdvancedCriteria cArray[] = {c1, c2};
    AdvancedCriteria appModCriteria = new AdvancedCriteria(OperatorId.AND, cArray);

    appModMasterDS.fetchData(appModCriteria, new DSCallback() {
    ...
    });

    The values from the criteria are not replaced when the sql query is generated resulting in error.

    If I use a normal Criteria instead of AdvancedCriteria, the values from the criteria are replaced in the generated query and things work fine. Unfortunately, I have to use AdvancedCriteria due to other requirements.

    I also tried using $criteria.criteria[1].APP_ID as was suggested in a similar post. In the case also, the resultant query was messed up (the whole criteria object string was replaced like for $criteria) as like:

    T_APP_MOD_MASTER.APP_ID(+) = '[{operator=and, criteria=[{fieldName=APP_ID, operator=equals, value=1}...]}]'[1].APP_ID and
    ...

    How do I form the whereClause in ds.xml so that I can use the values from
    the AdvancedCriteria correctly?

    Is there any other method that I can use? Can I pass the values through
    the DSRequest? How can I access the DSRequest attributes in the ds.xml?

    Thanks,
    Mouli

    #2
    Velocity expressions such as $criteria.criteria[1].APP_ID are correct, but your particular Velocity expression was wrong for the AdvancedCriteria arriving at the server - it points to a Criterion that has further sub-Criteria rather than an atomic value. Look at the server log to see the structure of the AdvancedCriteria you're actually passing, as it arrives on the server.

    If you can't figure out the right Velocity expression, another option is to use Java in a DMI to inspect the AdvancedCriteria, extract the criteria value you care about, and use dsRequest.addToTemplateContext() to make it available under some other variable name (eg just $APP_ID).

    Comment


      #3
      I am also having a very difficult time trying to get a whereClause in a ds.xml file working. Is there an example somewhere that show Java passing data to a whereClause in ds.xml?
      I tried passing it through HTTPParamters, a Session, and Criteria...still no luck. Please help. an example would be great.

      Comment


        #4
        There are several examples of custom <whereClauses> in the EE Showcase under Server Examples -> SQL.

        Comment

        Working...
        X