Announcement

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

    allowEmptyValue - not sending 'null' on update?

    if 'allowEmptyValue' is set to true for a field in a ds.xml, and that value is updated to a 'null' from some other value, should form.saveData() update that column with a null value?

    Currently, we have to do a setValue((Integer)null) in order to ensure the saveData() call updates the column with a null.

    Are we missing some other api call on the form to instruct it to update null values or something?

    #2
    If you clear out the field in the UI and save, the expected result would be an empty string sent to the server, which for a field of type "int" would be interpreted as a null.

    Are you seeing something different? If so can you show the DataSource definition, RPC tab request and response, and server log?

    Comment


      #3
      I'm getting the string null, when it should be empty.

      Isomorphic, we are not seeing the behavior that you are describing in our application.

      This behavior has been observed with the 4.0 release and 4.1 release. I generated this test and ran it with IE 10 and Chrome though I do not believe the browser matters here.


      Take a look at the request bodies below.

      Click save immediately:
      _operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml

      Click save after selecting a value from the pick list:
      NUMBER=One&_operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml

      Click save after selecting the empty value from the pick list:
      NUMBER=null&_operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml


      The very last request body should either not contain NUMBER or contain no value for NUMBER.

      This can easily be tested with the following code in an onModuleLoad():

      RestDataSource dataSource = new RestDataSource();

      SelectItem selectItem = new SelectItem("NUMBER", "Number");
      selectItem.setAllowEmptyValue(true);
      selectItem.setValueMap("One", "Two", "Three");

      dynamicForm = new DynamicForm();
      dynamicForm.setDataSource(dataSource);
      dynamicForm.setWidth(300);
      dynamicForm.setItems(selectItem);

      IButton button = new IButton("Save");
      button.addClickHandler(new ClickHandler() {
      @Override
      public void onClick (ClickEvent event) {
      dynamicForm.saveData();
      }
      });

      VLayout vLayout = new VLayout();
      vLayout.addMember(dynamicForm);
      vLayout.addMember(button);

      vLayout.draw();

      A response would be greatly appreciated.

      Thanks,
      Pat
      Last edited by tuckerpm; 1 Apr 2014, 11:27.

      Comment


        #4
        This looks to be unrelated to the original post - SelectItem as opposed to text field, RestDataSource as opposed to using the Server Framework (so we're talking about on the wire serialization rather than post-validation value received on the server)

        Can you clarify what you're doing - using the UI to pick the empty value? If so, what you're seeing in the third request is exactly what you should expect. The client-side system needs to convey that the user actually made an explicit choice of null.

        See also dataSourceField.nillable for some additional choices for how null is represented - this only applies to a POST with XML content, but then, that tends to be needed to disambiguate cases like these.

        Comment


          #5
          Wow, thanks for the quick response. Sorry I did not realize there was much of a difference in our two problems, he/she didn't specify a form item type.

          We are building a Smart GWT constructed input form to point at our current REST service. So basically we are trying to replicate the behavior of a normal HTML form with Smart GWT components.

          For instance if you have the following html form:

          <form name="input" action="some_where" method="post">
          <input type="text" name="name" />
          <select name="number">
          <option value=""></option>
          <option value="1">One</option>
          <option value="2">Two</option>
          <option value="3">Three</option>
          </select>
          <input type="submit" value="Submit">
          </form>

          You will get the following response bodies when doing the same tests as described above.

          name=&number=

          name=aname&number=1

          name=&number=

          Sending the value "null" when it should be empty will prevent us from actually saving the value "null", if it ever needs to be done.

          Thanks again for your quick response,
          Pat
          Last edited by tuckerpm; 1 Apr 2014, 10:54.

          Comment


            #6
            I went ahead and added a TextItem to the Smart GWT example that I posted above and ran the tests again.

            TextItem textItem = new TextItem("NAME", "Name");

            The request bodies are as follows:

            Before touching the form items:
            _operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml

            After adding values:
            NAME=name&NUMBER=One&_operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml

            After clearing:
            NAME=null&NUMBER=null&_operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml

            Even the TextItem returns the string null after its content is deleted. This seems really wrong to us.

            Thanks,
            Pat
            Last edited by tuckerpm; 1 Apr 2014, 10:47.

            Comment


              #7
              For both SelectItem and TextItem, you can change what is used as the empty value, so that it could be an empty string. But we'd advise against this, since using null is more semantically consistent - for example, it's what you'd typically store in a bean or a database, rather than empty string.

              If you switch to POST'ing or PUT'ing XML as suggested, you won't have ambiguity about null vs "null", and you'll also be in line with REST best practices.

              Comment


                #8
                The REST service was built to work with a standard HTML form. We aren't allowed to change the REST service to work with the new form, doing so could possibly introduce incompatibilities with the old form.

                How do you change what is used for the empty value?

                If a user were to type "null" into the TextItem, how do you tell the difference between the value specified by the user and the string "null" that your form is submitting?

                Thanks,
                Pat

                Comment


                  #9
                  A co-worker just pointed out that there are a lot of people in the world that have a last name of "null". How would these people get added to an application that is using a Smart GWT TextItem, for the last name input field, if the string null means no value is provided?

                  http://www.ancestry.com/name-origin?surname=null

                  Thanks,
                  Pat

                  Comment


                    #10
                    So again, the best solution here is to upgrade the REST service so it uses POST'd XML or JSON data, because that enables all 3 cases to be differentiated: no change, set to empty string, set to null. There is no way to do this with just query parameters.

                    However to cause a FormItem to use empty string instead of null when the field has been explicitly emptied, just set defaultValue to "".

                    Comment


                      #11
                      Well I thought it worked when I did my initial test but after setting the default value for all of our form items, I noticed that it is not working. so, I modified the test application from earlier posts and ran though the previous tests and I still get "null" in the request body. Results as follows:

                      NAME=&NUMBER=&_operationType=update&_oldValues=%7B%22NAME%22%3A%22%22%2C%22NUMBER%22%3A%22%22%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml


                      NAME=name&NUMBER=One&_operationType=update&_oldValues=%7B%22NAME%22%3A%22%22%2C%22NUMBER%22%3A%22%22%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml


                      NAME=null&NUMBER=null&_operationType=update&_oldValues=%7B%22NAME%22%3A%22%22%2C%22NUMBER%22%3A%22%22%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=xml


                      The difference from these tests and the original tests is only that the values are always in the request data. The problem where the string null is sent still exists. Please advise.

                      Thanks,
                      Pat
                      Last edited by tuckerpm; 3 Apr 2014, 06:06. Reason: I spoke to soon. :(

                      Comment


                        #12
                        Any idea what we can do to get the value set back to the empty string instead of the string null after the user clears the FormItem? We really need to get this working properly.

                        Thanks,
                        Pat

                        Comment


                          #13
                          Hi
                          Sorry for the confusion - yes you can set the attribute "emptyStringValue". For now this is undocumented, and you have to use the "setAttribute" API to do this (just myItem.setAttribute("emptyStringValue", "");) but we will be adding a proper setter method for this in the near future.

                          Regards
                          Isomorphic Software

                          Comment


                            #14
                            That did the trick for the TextItem but the SelectItem still sends the string null. We are one step closer now.

                            Thanks,
                            Pat

                            Comment


                              #15
                              Incorporate the empty value into the valueMap with "" as the ID instead of using the allowEmptyValue setting.

                              Comment

                              Working...
                              X