Announcement

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

    Why does ListGrid.getShowFilterEditor() return null instead of false at start?

    If you create a ListGrid and try to find out if the FilterEditor is displayed, you call:
    Code:
    ListGrid.getShowFilterEditor()
    The result is a null instead of a false.
    So if in your code you conditonally display the FilterEditor based on some condition, and you want to test whether the filterEditor is displayed or not, you have to do:

    Code:
    if (ListGrid.getShowFilterEditor() == null || !ListGrid.getShowFilterEditor())
    Is this practical or can we call it a bug?

    PS: I am using SmartGWT 3.0

    #2
    I was searching forums today looking for some FilterEditor questions and found your question. I don't know if you still need it, probably you have figured it out yourself but my guess is that SmartGWT is a wrapper around javascript library and all the attributes that hasn't been set by you returns null. Javascript does not need boolean variable to be initialized to check for the "true" state. Therefore attributes (especially boolean) are not set by SmartGWT if their default behavior is supposed to be false.

    Comment


      #3
      Originally posted by raivis
      I was searching forums today looking for some FilterEditor questions and found your question. I don't know if you still need it, probably you have figured it out yourself but my guess is that SmartGWT is a wrapper around javascript library and all the attributes that hasn't been set by you returns null. Javascript does not need boolean variable to be initialized to check for the "true" state. Therefore attributes (especially boolean) are not set by SmartGWT if their default behavior is supposed to be false.
      Thank you for your answer. It seems logic but the point I was raising was the need for 2 if conditions instead of 1 and was wondering why the variables are set to null and not to their "java" default values (boolean false, int 0, ...)

      Comment


        #4
        It actually returns class variable Boolean, not primitive boolean. Therefore it's initial value "null" is correct.
        However I do agree with you about the double checking. I used to think that
        Code:
        if (ListGrid.getShowFilterEditor()) { // or any other Boolean attribute
           // TRUE part
        } else {
           // FALSE part
        }
        should work as it's translated to javascript eventually. Due to your question I tried one testcase and for some reason it does not work. I got an exception that was swallowed by framework and I never knew there was an error before. I guess it's realted how gwt compiler translates null objects to javascript.
        Last edited by raivis; 30 May 2012, 04:31.

        Comment


          #5
          FYI this is a common pattern for a value that can be set true or false or left null in which case it is dynamically defaulted based on other settings.

          Comment

          Working...
          X