Announcement

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

    Offline DSRequest, how to order programmatically?

    Hello,
    (SmartGWT 3.0 release)

    I am building a public webservice (in a servlet, to provide an API to my SmartGWT app for external apps to pull some data from my app), that makes use of the (offline) DSRequest/DSResponse to fetch the data from my MySQL Table, and return JSON in a certain way.

    I want to be able to specify ordering programmatically. How to do this?

    I tried:
    Code:
    List<String> sorts = new ArrayList<String>();
    for (int i = 0; i < json.size(); i++) {
    	JSONObject cur = (JSONObject) json.get(i);
    	sorts.add(cur.getString("property"));
    }
    req.setSortBy(sorts);
    But this doesn't seem to work, that is, in the generated query I don't see ORDER BY <field1>, ... etc.

    My operationbinding does not have a <orderBy> clause set, so it should use these sorts, right?

    Also, I could not find how I could specify the Sort Order (ASC or DESC)

    #2
    That's the right way to request sorting. Use a "-" prefix for descending sort.

    As far as not seeing the sorting, can you put together code we can run to see the effect? Eg a DMI to be added to a sample DataSource.

    Comment


      #3
      Further note - there's no need to build anything to allow external apps to use your DataSources - the RestHandler servlet just provides this with no work at all. You only need to build your own if you have specific requirements for the format of XML or JSON messages.

      Comment


        #4
        Aha, it works now, it was a small bug in my url-encoding of GET parameters. Should've seen it with the debugger, deciding what to blame at the moment, think I'm going for the 'lack of coffee' option. :-)

        Thanks! It's a great system.

        ------------------
        PS:
        Originally posted by Isomorphic
        Further note - there's no need to build anything to allow external apps to use your DataSources - the RestHandler servlet just provides this with no work at all. You only need to build your own if you have specific requirements for the format of XML or JSON messages.
        Alright thanks. Yet it is the case that I need to format the JSON, so this method works just fine at the moment. I do will look into the option you gave me, since I haven't so far. What docs should I look in?

        Comment

        Working...
        X