Announcement

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

    Expected Behavior of SortNormalizer.normalize()?

    Hello Forum,

    My Environment: SmartGWT 4.0 LGPL | GWT 2.51 | Chrome version 40.0.2214.115 m

    The cowboys whose code I'm debugging — and whom I swear I'm going to kill if I ever get the chance — have a ListGridField defined like so...
    Code:
       ...
    1)   cowboyCoded = new ListGridField("cowboyCoded");
    2)   cowboyCoded.setSortNormalizer(new SortNormalizer() {
    3)   @Override
    4)   public Object normalize(ListGridRecord record, String [b][i][u]fieldName[/u][/i][/b]) {
    5)      SC.logDebug("I HATE FRICK'N COWBOY CODERS!") // I added this...
    6)      return cowboyCodedValueMap.get(record.getAttributeAsString("cowboyCoded"));
          }
       });
       ...
    The cowboy coder's umpteenth bug I'm currently debugging is...
    • ...the 'cowboyCoded' column does NOT sort when its column header is clicked on.

    I put a breakpoint at line 6. Plus, I have added the SC.logDebug() call at line 5.

    You can safely assume that my IDE's debugger is working perfectly. And you would also be correct to assume that my logging is correctly configured at the right log level.

    Here are some of my own assumptions...
    1. ...that the DataBoundComponent in question is doing client-side sorting (I'm 99% certain of this based on what I DO see in the SmartGWT Dev Console logs plus what I DON'T see in my server logs)
    2. ...that the ListGrid|ResultSet|DataSource is NOT in 'Paged Mode' — which I will eventually confirm is or isn't (with your help, hopefully, because I unashamedly confess: At this very moment that I'm writing this, I don't know yet how to determine that).
    3. ...that the meaning of 'normalize' in the context of RecordList.SortNormalizer.normalize() is the same meaning as 'normalize' in this context and not in this context.
    4. ...that my questions (below) are general enough that they could be answered without me having to provide a stand-alone test case to reproduce the cowboy behavior I'm observing. In other words, I assume that the only thing needed to answer my questions (below) is deep, expert knowledge of SmartGWT (which I unashamedly admit, I lack — at this point).


    Debugging in Development Mode in my IDE, this is what I do...
    1. ...I launch in my browser, the View (a ListGrid) that contains the ListGridField defined in the above source code snippet...
    2. ...when the ListGrid View successfully loads, I sort the "cowboyCoded" column of the ListGrid by clicking on its column header

    This is what I expect...
    • ...to see "I HATE FRICK'N COWBOY CODERS!" in my console/logs...
    • ...my IDE's debugger to fire up and pause at the breakpoint at line 6 in the source code snippet above...
    • ...the 'cowboyCoded' column to be sorted when its column header is clicked on.


    However, this is what actually happens...
    • ...the string "I HATE FRICK'N COWBOY CODERS!" is nowhere to be found in my console/logs...
    • ...my IDE's debugger does indeed fire up and the debugger does indeed pause at other breakpoints I have set at other points in the source code (not shown above). But it NEVER EVER pauses at the breakpoint at line 6 in the source code snippet above...
    • ...the 'cowboyCoded' column does NOT get sorted when its column header is clicked on.

    Finally, here are my questions...
    1. ...what flag(s) should the cowboy's have set in order for their module I'm now debugging to produce the expected behavior? On what class is that flag?
    2. ...should I expect the SortNormalizer.normalize() to be called when I click on the column header to trigger a sort?
    3. ...if 'No' to the preceding question, how then, can I trigger — from the View — SortNormalizer.normalize() to be called?
    4. ...assuming I can somehow manage to get SortNormalizer.normalize() to be called (by maybe switching on the right flag) then in that case, would refactoring the above snippet to the following, have any bearing whatsoever on anything?


    Code:
      ...
      [b][i]import java.text.Normalizer;[/i][/b]
      ...
    1)   cowboyCoded = new ListGridField("cowboyCoded");
    2)   cowboyCoded.setSortNormalizer(new SortNormalizer() {
    3)   @Override
    4)   public Object normalize(ListGridRecord record, String [b][i][u]fieldName[/u][/i][/b]) {
    5)      SC.logDebug("I HATE FRICK'N COWBOY CODERS!") // I added this...
    6)      String cowboyNormalized = cowboyCodedValueMap.get(record.getAttributeAsString([b][i][u]fieldName[/u][/i][/b]));
    7)      return [i][b]Normalizer.normalize( cowboyNormalized,  Normalizer.Form.NFC ) ); // I MIGHT add this...[/b][/i]
          }
       });
      ...
    Thank you in advance for sharing your SmartGWT expertise with the community.

    Yahoo-Yippie-I-Aye! ;)

    Peace.
    Last edited by cowboy.coder.killer; 21 Feb 2015, 11:00.

    #2
    You have the right sense for "normalize".

    The behavior you're seeing suggests that someone has simply set listGridField.canSort to false. This would cause sorting not to be performed at all, so the normalizer would never be invoked.

    This would be indicated by the sort arrow not appearing in the column header, which normally happens if a column is sorted.

    Comment


      #3
      Thank you sincerely for your speedy reply.

      ListGridField.setCanSort(false) really was one of my first lines of investigation (great minds do indeed think alike ;)).

      I've established that there are no calls whatsoever to ListGridField.setCanSort() in the entire app. I should add: I'm not at work today and so I don't have the code to hand. The snippets I posted earlier are from memory (I've stared at that particular block of code at work for so long now, that unfortunately it's burned indelibly into my skull). But you can trust me when I say I did indeed search for ListGridField.setCanSort() 2 days ago at work. And I found nada. I will confirm that when I return to work on Monday.

      In the meantime, can you think of anything else that might also cause the observed 'shuffle-instead-of-sort' behavior?

      I can also add right now (again from my memory of intense debugging sessions earlier this week at work)...
      • ...when the ListGrid in question is first loaded, the ListGridField that is passed to ListGrid.setSortField(...) is indeed the column on which the ListGrid is initially sorted. That is, when the ListGrid is loaded for the very first time, it is sorted on the column that was passed into ListGrid.setSortField(). The problem is, when I click on the column headers, that only shuffles the column out of their expected sorting order. The same thing also goes for every other column in the grid that you click.
      • ...again, this grid exhibits client-side sorting behavior. That is, when I click on the column headers, there is no 'Loading' status spinner which I ordinarily take to mean: 'a call to the server is being made'. Plus, the SmartGWT Dev Console tells me that 100% of the records that are in the grid at that time, came from the cache (which, I presume, was eagerly-loaded onModuleLoad()). Plus, Hibernate records no corresponding SQL calls in the logs — as it does on other data fetches from the server — for the particular set of records in the grid at the time.
      • ...the app in question uses GwtRpcDataSource.


      Again, my questions are...
      1. ...although I'm pretty close to 100% certain that client-side sorting behavior is indeed what I am observing, what can I check to confirm that is indeed the case? Please?
      2. ...what can I check to confirm whether 'Page Mode' is being used or not?
      3. ...what else (besides ListGridField.setCanSort(false)) might make it appear as if sorting has been switched off for every column in a ListGrid?


      Thanks again in advance for your expert advice.

      P.S. Have you guys ever condidered fleshing out the javadoc of your SortNormalizer.normalize() method to include something similar to Java's Normalizer javadoc? Yours is currently very vague. And for folks like me whose experience is mostly on the backend, in the absence of any explanation whatsoever, there could be a risk of others confusing it with the more widely-known meaning of 'normalize'.
      Last edited by cowboy.coder.killer; 21 Feb 2015, 14:25.

      Comment


        #4
        UPDATE...

        My Environment: SmartClient Version: v9.0_2013-07-03/LGPL Development Only (built 2013-07-03) ...

        Comment

        Working...
        X