Announcement

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

    How to use Object returned by FormItem.getValue()

    I have a ListGrid and need to allow users to set the values in multiple rows they have selected via a DynamicForm. When the user selects rows and clicks a button I display a form set to the same DataSource as the grid and populate the form with the editable ListGridField names. All works well and the fields show up as expected.

    I then iterate over the selected grid rows using ListGrid.getSelection(), apply the form field values to the corresponding ListGridField in each row using ListGridRecord.setAttribute() and then call ListGrid.updateData(currentRow) to do the update.

    Everything works fine for text fields, but I also have some "intEnum" fields. When I use ListGridRecord.setAttribute("FieldName", FormItem.getValue()) for these fields I can see in the server log that the DSRequest payload has the "intEnum" fields set to an empty object, for example MyIntEnumField:{}

    I've tried changing the field type to "enum" but then I get MyIntEnumField:"1" when it should be MyIntEnumField:1

    What am I doing wrong?

    #2
    What kind of FormItem is that, and what type of object is FormItem.getValue() returning? This may just be a matter of typecasting.

    Note that even if the client-side value is submitted as "1" instead of 1, the server knows the field type (if it's intEnum) and will convert it for you.

    Comment


      #3
      I'm doing it generically by iterating over the selected grid records and then iterating over the form fields and setting the value of the record attribute to the form item's value. Here's the actual code.
      Code:
      for (ListGridRecord rec : itemGrid.getSelection()) {
        for (FormItem formItem : form.getFields()) {
      	rec.setAttribute(formItem.getName(), formItem.getValue());
        }
        itemGrid.updateData(rec);
      }
      I discovered the problem. It isn't actually with the value being moved from formItem to the ListGrid record correctly. The problem is when the update operation is submitted to the server the DSRequest.getOldValues and DSRequest.getValues return identical maps. I have server side code that prunes the getValues() map of identical values so the SQL statement won't include fields that haven't changed.

      Is there a reason why oldValues would be populated the same as the "new" values? Is there a better technique I should be using?

      Comment


        #4
        Ah - so the problem is that what you're doing is effectively changing the client-side cache directly, which is semantically equivalent to saying that a change has already occurred server-side. A clearer approach is to create a new Record from the combined data, and use that with DataSource.updateData() instead. In that case there will be no oldValues, or you can take the existing ListGridRecord's data and send it as oldValues to be formally correct.

        Comment


          #5
          I tried that. I created a new Record and setAttribute() for the PK field and the fields I want to update. But on the server getOldValues() still returns the same map as getValues(). Only now it has only the fields I've put into it along with something of unknown origin "__ref:{}". It also had the side effect of clearing the value of all fields in the listgrid except for those in the new record.

          How do I take the list grid record and "send it as oldValues to be formally correct."

          values:{
          __ref:{},
          ISKU:"22657",
          IATT04:"2"
          } ....

          oldValues:{
          __ref:{},
          ISKU:"22657",
          IATT04:"2"
          } ....
          Last edited by jay.l.fisher; 8 Dec 2009, 15:16.

          Comment


            #6
            So to be formally correct, you'll add oldValues to the dsRequest yourself (it's settable).

            Another approach is to setEditValues on the grid (editValues mean uncommitted edits - see the editing overview) and call saveAllEdits(). This is basically the equivalent of the user editing the record in the grid and then saving.

            Comment


              #7
              I looked for a method in DSRequest like setOldValues() but didn't find anything. Should I use dsr.setAttribute("oldValues", rec)?

              I'll try using setEditValues and saveAllEdits(). It sounds like the best route. But I would like to know how to set oldValues in case I need to in another context.

              Thanks!

              Comment

              Working...
              X