Announcement

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

    customds and criteria

    Using
    smartgwtpro-3.0p
    customds

    I try to retrieve data from a customds using a call to fetchData:
    Code:
    final DataSource ds = DealerUploadDS.getInstance();
    		
    		ds.fetchData(new Criteria("userName", userName), new DSCallback() {
    In dev mode this works, but when I compile the gwt the "username" attribute contains a linkedMap.
    Code:
    dsRequest.getCriteria().get("userName").toString()
    result (in eclipse):
    {userName={0=N, 1=I, 2=S, 3=1, 4=3, 5=0, 6=7, 7=1, cM={1=1, 317=1, 320=1, 323=1}}}

    How can i pass a filter criteria to a datasource fetchData call?
    Last edited by meindert; 28 Aug 2012, 01:36. Reason: quation missing

    #2
    Is this code copied and pasted? If so, you have a case error ("userName" vs. "username"). There's no good general-purpose solution to dealing with GWT's lack of reflection right now, but I would strongly recommend creating an enum or at least some String constants to hold your field names to prevent mismatches.

    Comment


      #3
      Fixed the case, the variable has got a different name, so was not the issue.
      I get a value for the field, but it's not a string it's a map for each individual character.

      Comment


        #4
        GWT does some odd things, and the combination of SmartClient+GWT is even odder, so what you're seeing may not necessarily be the behavior that's causing the problem. First, is the first code block client-side and the second server-side, or are they both client-side? Next, try displaying (via gwt-log or something similar) the results of this on both the client and server sides running in compiled mode:

        Code:
        "class: " + userName.getClass() + ", toString: '" + userName.toString() + "'"
        This will show what representation GWT has for your userName (a String object?) in the emulated Java on the client side and how it's being interpreted on the server side. Finally, if this shows that the odd behavior is being exposed like it appears it is, look on the RPC section of the SmartGWT dev console to see what SmartGWT is trying to transmit and what the actual request body looks like.

        Comment


          #5
          I'm on the server side using a customds as in the example
          The debug line returns:
          class: class org.apache.commons.collections.map.LinkedMap, toString: '{0=N, 1=I, 2=S, 3=1, 4=3, 5=0, 6=7, 7=1, cM={1=1, 317=1, 320=1, 323=1}}'

          The RPC call says the same:
          "data":{
          "userName":{
          "cM":{
          "1":1,
          "317":1,
          "320":1,
          "323":1
          }
          }
          Funny enough it depends, sometimes it seems to work and sometimes it doesn't...

          It's quite a mission to test because its only happens on compiled GWT.

          I think the criteria might be in fact a advancedCriteria, and that the pro-version I have does not support this?
          dsResult.getCriteria() returns a map, how would I get this converted to the criteria I created when performing the fetch?

          I'm trying the following code now to see if this works
          Code:
          Criteria c = new Criteria();
          		c.addCriteria(new Criteria("dummy", "dummy"));
          		c.addCriteria(new Criteria("userName", userName));
          		ds.fetchData(c, new DSCallback() {
          I think this might work because I read somewhere that a criteria is a advanced criteria unless it has more then one attribute and a 'AND' operator?
          Last edited by meindert; 28 Aug 2012, 03:12. Reason: added broken RPC request

          Comment


            #6
            http://smartclient.com/smartgwtee/se...#getCriteria()

            Comment


              #7
              I couldn't find anything in those documents on how to fix my issue (or if I was doing the datasource.fetch wrong)

              I have put the following workaround in place, but would still like to find out why this is happening?

              Code:
              for (Object key : dsRequest.getValues().keySet()) {
                //Workaround for the bug that a string value comes in as a LinkedMap (on compiled GWT only)
                 if (dsRequest.getValues().get(key.toString())  instanceof LinkedMap){
                   LinkedMap mappedString = (LinkedMap) dsRequest.getValues().get(key.toString());
                   StringBuffer stringValue = new StringBuffer();
                   for (int j = 0; j < mappedString.size(); j++) {
                      if (mappedString.get(j+"")!=null){
                        stringValue.append(mappedString.get(j+""));
                      }
                   }
                   filterCriterias.put(key.toString(),stringValue.toString()) ;
                 }else{
                   filterCriterias.put(key.toString(), dsRequest.getValues().get(key.toString()).toString());
                 }
              }

              Comment


                #8
                See the FAQ about Strings serialized as Arrays. This is a bug in core GWT.

                Comment

                Working...
                X