Announcement

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

    ds.xml criteria data type on operation binding

    I have an operation binding in my ds.xml for a custom fetch operation defined as:
    Code:
    <operationBindings>
      <binding operationType="fetch" operationId="findActiveTriggers" serverMethod="findActiveTriggers" >
        <criteria operator="equals" fieldName="enabledOpsfield" value="true"/>
      </binding>
    </operationBindings>
    where the field in question is defined in that same ds.xml as:
    Code:
    <field name="enabledOpsfield" type="boolean">
    When that custom fetch is executed, The AdvancedCriteria on the server has the value as a string set to "true" whereas if I use a filter and set the same field it comes to the server as a Boolean.

    Is there any reason the custom fetch with the binding is not used the defined datatype of that field or is there something I can do to have it use a Boolean instead of a String? Is there a type attribute for the criteria xml?

    #2
    Right now, there isn't support for automatically converting the value based on the field type, so you need to use the general Component XML way of explicitly declaring the value type inline:

    Code:
    <criteria operator="equals" fieldName="enabledOpsfield">
       <value xsi:type="boolean">true</value>
    </criteria>
    Note that, while direct access to the AdvancedCriteria will show a String, subsequent processing by the built-in DataSources would handle that String properly as a boolean. So the above is only necessary if you have custom logic manipulating the AdvancedCriteria and you prefer not to handle a possible String value at that point.

    Comment


      #3
      Excellent thanks I will do that.

      When I added the code above so that it now looks like this:
      Code:
      <binding operationType="fetch" operationId="findActiveTriggers" serverMethod="findActiveTriggers" >
        <criteria operator="equals" fieldName="enabledOpsfield">
          <value xsi:type="boolean">true</value>
        </criteria>
      </binding>
      I get the following parsing exception:
      Code:
      XML parser fatal error: file '/xxx/war/ds/trigger.ds.xml' line 195: org.xml.sax.SAXParseException; systemId: file:///xxx/war/ds/trigger.ds.xml; lineNumber: 195; columnNumber: 33; The prefix "xsi" for attribute "xsi:type" associated with an element type "value" is not bound.
      Exception loading DataSource trigger: com.isomorphic.xml.XMLParsingException: [
          "XML parser fatal error: file '/xxx/war/ds/trigger.ds.xml' line 195: org.xml.sax.SAXParseException; systemId: file:///xxx/war/ds/trigger.ds.xml; lineNumber: 195; columnNumber: 33; The prefix \"xsi\" for attribute \"xsi:type\" associated with an element type \"value\" is not bound."
      ]
      	at com.isomorphic.xml.XML.parseXML(XML.java:206)
      	at com.isomorphic.xml.XML.parseXML(XML.java:125)
      	at com.isomorphic.xml.XML.toDSRecords(XML.java:328)
      	at com.isomorphic.xml.XML.toDSRecords(XML.java:320)
      	at com.isomorphic.xml.XML$RecordsFromXMLCache.loadObjectFromFile(XML.java:442)
      	at com.isomorphic.store.ProcessedFileCache.getObjectFromFile(ProcessedFileCache.java:141)
      	at com.isomorphic.xml.XML.loadCacheableDSRecords(XML.java:453)
      	at com.isomorphic.store.DataStructCache.loadInstance(DataStructCache.java:179)
      	at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:65)
      	at com.isomorphic.datasource.DataSource.forName(DataSource.java:230)
      Do I have something wrong?

      If i remove the "xsi:" it parses ok but then I execute the fetch I get the following exception:
      Code:
      2014-05-23-11:41:24:167 -0400   WARN [http-bio-8080-exec-7] dsRequest.execute() failed: 
      java.lang.ClassCastException: org.apache.commons.collections.map.LinkedMap cannot be cast to java.lang.String
      	at com.isomorphic.rpc.RPCManager.applyEarlierResponseValues(RPCManager.java:2558)
      	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2525)
      	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:215)
      	at com.stonebranch.opswise.server.OpswiseServlet.handleDSRequest(OpswiseServlet.java:149)
      Last edited by stonebranch1; 23 May 2014, 07:42.

      Comment


        #4
        Yes. It's not well-formed XML unless you declare the prefix.

        This isn't a SmartGWT-specific thing, but just so you don't have to look it up, adding this attribute to your root element (<DataSource>) will fix the XML.

        Code:
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        Comment


          #5
          Thank you kindly.

          Comment


            #6
            Almost there, the Boolean seems to get passed in but before our code gets called the following exception is thrown so I am not sure if I am missing something else?

            Code:
            2014-05-23-12:00:24:198 -0400   WARN [http-bio-8080-exec-7] dsRequest.execute() failed: 
            java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
            	at com.isomorphic.rpc.RPCManager.applyEarlierResponseValues(RPCManager.java:2558)
            	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2525)
            	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:215)

            Comment


              #7
              Hmm, this is caused because we allow you to provide a Velocity expression there, so we are assuming String.

              We'll go ahead and adjust this code to allow a non-string type here, however, what we'd advise is just having your code that handles AdvancedCriteria automatically deal with a String value. It's not illegal for the value to be provided as a String at this point, so this could come up with other subsystems, even if you are explicit about wanting a boolean here (and we resolve the issue that prevents doing so..).

              Comment


                #8
                Agreed and I am in fact making sure we handle the String as well.

                Once again thanks.

                Comment

                Working...
                X