Announcement

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

    Cannot set null value in FormItem

    I'm trying to set programatically a null value in a FormItem (really an IntegerItem), sice I want to clear its actual value, whatever it is. I have the following code:

    Code:
    item.setValue((Integer)null);
    this:

    Code:
    Integer nulo = null;
    item.setValue(nulo);
    and this:

    Code:
    private Integer getNull() {
      return null;
    }
    item.setValue(getNull());
    But it always gets translated to this:

    Code:
     2616 com_smartgwt_client_widgets_form_fields_FormItem_$setValue__Lcom_smartgwt_client_widgets_form_fields_FormItem_2I(alertItem, null.nullMethod());
    Which generates an exception, since null does not have methods. So, how can I clear the value of a FormItem element? Can I force it to have a null value in any way?

    #2
    I dont know if this would work since I hvnt used IntegerItem.

    But a possible work around would be to use item.setValue("") and on the server simply put a check if (value=="") then value=null;

    Since it must be a part of a form, you could also do form.clearValues which simply clears all values.

    I checked the API for IntegerItem which says that the default value it accepts is null so passing null doesnt seem to be the likely problem. I guess its the casting that is probably throwing the exception but again i m not sure.

    Hope you could run some checks to confirm this.

    Cheers,
    Hetal

    Comment


      #3
      The signature in SmartGWT is FormItem.setValue(int value). The reason item.setValue((Integer)null) compiles successfully is due to JDK 1.5 autoboxing but passing a null Integer to a method that accepts "int" will rause a null pointer exception. This is a pitfall of using autoboxing.

      You could try setValue((String) null) to set a null value, but we'll look into changing the various setValue(..) method to accept the primitive wrapper class instead.

      Comment


        #4
        Thanks, it worked casting it to String.

        Comment


          #5
          See also DynamicForm.clearValue(fieldName). We'll add a helper on FormItem so this is easier to find.

          Comment

          Working...
          X