Announcement

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

    Request DataSource Ignore Null Values

    SmartClient Version: v8.3p_2013-01-22/LGPL Development Only (built 2013-01-22)

    FF 17.0.3 ESR

    GWT 2.5

    Windows 7

    Executed test in FF 17.0.3 ESR browser itself
    ---

    In a followup to my question from yesterday, is it possible to have the DataSource ignore null values from the ingested JSON? I have fields that may define the value null, which is interpreted as an empty String. The end result is a databound ComboBoxItem with empty entries/blank rows. Do I need to override transformResponse?

    #2
    Possibly, but you haven't showed what null values are present or for what type of fields, so we can't say yet..

    Comment


      #3
      Originally posted by Isomorphic View Post
      Possibly, but you haven't showed what null values are present or for what type of fields, so we can't say yet..
      Ok, here is my JSON:

      Code:
      {
          "Info": 
          [
              {
                  "field1": "field1",
                  "field2": "field2",
                  "field3": "field3",
                  "field4": "field4",
                  "field5": "field5"
              },
              {
                  "field1": "field1",
                  "field2": null,
                  "field3": "field3",
                  "field4": "field4",
                  "field5": null
              }
          ]
      }
      Here is my post from yesterday: http://forums.smartclient.com/showthread.php?t=25542

      SmartGWT interprets the null as an empty string at the moment.

      Comment


        #4
        Any idea Isomorphic?

        Comment


          #5
          Best fix here is to revise the service not to send this data (waste of bytes).

          Alternatively, either transformResponse or a FieldValueExtractor could be used to end up with null as a value instead of "".

          Comment


            #6
            I used the FieldValueExtractor on my DataSourceTextField to check if the String is null or empty, and simply return a null. However, the ComboBoxItem is still populated with the blank values. I know it would be ideal not to send null or empty, but in my case, that's what I am left with. Is there a way to have the null value simply ignored by the ComboBoxItem?

            Comment


              #7
              What specifically do you want the ComboBox to ignore?

              Blank string vs null doesn't display any differently in a picklist.

              Are you trying to ignore records that consist entirely of null fields?

              Comment


                #8
                Originally posted by Isomorphic View Post
                What specifically do you want the ComboBox to ignore?

                Blank string vs null doesn't display any differently in a picklist.

                Are you trying to ignore records that consist entirely of null fields?
                Sometimes the field contains a null, other times it doesn't. I would like to ignore those records that contain a null.

                Comment


                  #9
                  Still pretty vague.. are you saying ignore the entire record if any one field contains a null? This is something you could implement in transformResponse().

                  Comment


                    #10
                    Originally posted by Isomorphic View Post
                    Still pretty vague.. are you saying ignore the entire record if any one field contains a null? This is something you could implement in transformResponse().
                    No, if say you have 5 fields. If one of the five fields contains a null, just ignore that 1 field and allow the rest to go through.

                    Comment


                      #11
                      OK, a "record" means one of these:

                      Code:
                              {
                                  "field1": "field1",
                                  "field2": "field2",
                                  "field3": "field3",
                                  "field4": "field4",
                                  "field5": "field5"
                              },
                      This:

                      Code:
                                  "field5": "field5"
                      .. is not a record, it's just a field and it's value.

                      What do you want the ComboBox to ignore - a record or a field value?

                      If you mean a field value, in what way is the ComboBox *not* ignoring it? As we've just said, null and empty string look the same in the picklist.

                      Comment


                        #12
                        Originally posted by Isomorphic View Post
                        OK, a "record" means one of these:

                        Code:
                                {
                                    "field1": "field1",
                                    "field2": "field2",
                                    "field3": "field3",
                                    "field4": "field4",
                                    "field5": "field5"
                                },
                        This:

                        Code:
                                    "field5": "field5"
                        .. is not a record, it's just a field and it's value.

                        What do you want the ComboBox to ignore - a record or a field value?

                        If you mean a field value, in what way is the ComboBox *not* ignoring it? As we've just said, null and empty string look the same in the picklist.
                        I want the ComboBox to ignore the null or empty field value. When the null or empty value is received, it comes through as an empty string and an "empty" value is put into the picklist. For instance,

                        Code:
                        abc
                        
                        cde
                        def
                        ghi
                        
                        ijk
                        I don't want the empty rows to appear is what I am saying.

                        Comment


                          #13
                          Now we're clear.

                          You could use transformResponse to get rid of these records.

                          More generally, this would typically be thought of as applying criteria to the records. For example, if you were talking to a service based on the SGWT server, you could eliminate those records with a NOT_NULL Criterion.

                          You can do the same if you apply optionCriteria to the ComboBox and set filterLocally, but this will load all data from the service so paging won't be possible.

                          This assumes you are using transformResponse to keep the null fields null and avoid the default conversion to empty string.

                          Comment


                            #14
                            Originally posted by Isomorphic View Post
                            Now we're clear.

                            You could use transformResponse to get rid of these records.

                            More generally, this would typically be thought of as applying criteria to the records. For example, if you were talking to a service based on the SGWT server, you could eliminate those records with a NOT_NULL Criterion.

                            You can do the same if you apply optionCriteria to the ComboBox and set filterLocally, but this will load all data from the service so paging won't be possible.

                            This assumes you are using transformResponse to keep the null fields null and avoid the default conversion to empty string.
                            Is there something wrong with not using transformResponse? Such as,

                            Code:
                            AdvancedCriteria criteria = new AdvancedCriteria("field5", OperatorId.INOT_EQUAL, "");
                                     
                            theComboBox.setOptionCriteria(criteria);
                            theComboBox.setFilterLocally(true);

                            Comment


                              #15
                              That's fine too, and it's sufficient assuming:

                              1. you have no other consumers of this data that need null values rather than empty string

                              2. empty fields will always end up with "" (as opposed to null). If null is also possible (eg your JSON service will completely omit certain fields) you could just adjust the criteria to also include NOT_NULL.

                              Comment

                              Working...
                              X