Announcement

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

    setAllowEmptyValue(true) does not work with update operation

    Hello,

    In SmartClient Version: SC_SNAPSHOT-2011-11-08/PowerEdition Deployment (built 2011-11-08).


    When updating an existing record in a form with a selectItem that allows an empty value:

    Code:
    final SelectItem teaSel = new SelectItem("Teacher_id", "Teacher");
    teaSel.setOptionDataSource(DataSource.get("Teacher"));
    teaSel.setValueField("Teacher_id");
    teaSel.setDisplayField("surname");
    teaSel.setAllowEmptyValue(true);
    When i select the empty value in the selectitem, and save the form using:
    Code:
    form.saveData();
    It should mean that Teacher_id will be persisted to NULL. Instead it does not send this field to the server at all, thus the update method leaves it untouched. So the Teacher_id value stays at its old value instead of being NULL'd.

    I remember this used to work before, so is it a small regression? All my forms with this kind of behaviour throughout my app suffer from this.

    #2
    This could be influence by DataSource and form settings and depends on what kind of DataSource it is (REST, SGWT server, etc). Can you make this into a minimal test case? Then we can take a look.

    Comment


      #3
      Will try.


      Some details already:
      1. I use smartgwt server , and the datasource is a normal SQL datasource.
      2. The field is not being sent to the server, ie. it's just not present in the json object sent to the server.


      Also, so far it seems that it happens with foreign keys, as this Datasource definition shows. The Teacher_id and Location_id are set using a SelectItem, and shows the problem. The SQL definition allows null for the fields Teacher_id and Location_id, obviously.

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <DataSource ID="LectureTemplate" serverType="sql" tableName="LectureTemplate"> 
        <fields> 
          <!-- Id, with primaryKey -->  
          <field name="LectureTemplate_id" type="sequence" primaryKey="true"/>  
      
      ...
          <field name="Course_id" type="integer" foreignKey="Course.Course_id"> 
            <validators></validators> 
          </field>  
          <field name="Teacher_id" type="integer" foreignKey="Teacher.Teacher_id"> 
            <validators></validators> 
          </field>  
          <field name="Location_id" type="integer" foreignKey="Location.Location_id"> 
            <validators></validators> 
          </field>  
        </fields>  
        <operationBindings> 
          <operationBinding operationType="update" requiresAuthentication="true" requiresRole="CAN_UPDATE_LECTURETEMPLATE"> 
          </operationBinding>  
        </operationBindings> 
      </DataSource>

      Comment


        #4
        Finally had time to create a stand-alone testcase (see link). It is an Eclipse project + sql file to import as tables with relevant test data. I removed the /lib/ dir et al., to reduce file size.

        http://www.sytematic.nl/SGWTTestCase.zip

        What to do to reproduce the problem:
        0. Run the included .sql file to obtain the table structure + test data
        1. Run the app
        2. Set the Teacher or Location field to 'empty'
        3. Click Save button
        4. Observe that the database still has Location_id = 1, rather than NULL

        I wonder what causes this!

        Comment


          #5
          Thanks for your effort, but we don't take Eclipse projects as test cases (too many possibilities for there to be an issue in the project itself and too much time to set up). If this is a real bug, it should be trivial to modify one of the sample projects (eg builtInDS) to demonstrate it - then you can just post the changes and we can try it very easily, with no possibility of time blown troubleshooting .project files.

          Comment

          Working...
          X