Announcement

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

    Nested forms not updating

    SmartGWT 4.1
    SmartClient Version: v9.1p_2014-11-09/PowerEdition Deployment (built 2014-11-09)

    I have created a very simple form that makes use of nested fields. When I programattically call setValues for fields that are nested they update in the UI as expected, however for fields that contain nested values they do not. I am curious what the proper methodology is, and if I am truly expected to tell these form items to redraw?

    nested object ds
    Code:
    <DataSource beanClassName="simpleNestedObject"
    ID="SimpleNestedObject">
    <fields>
    <field name="a" type="float"/>
    <field name="b" type="float"/>
    <field name="c" type="text"/>
    </fields>
    </DataSource>
    SimpleForm.java -- Nested object fields do not update without redrawing FormItems
    Code:
    public class SimpleForm extends VLayout {
     private final DynamicForm form;
    
     public SimpleForm() {
      form = new DynamicForm();
      form.setDataSource(new DataSource() {
       public DataSource init() {
        DataSourceField nested = new DataSourceField();
        nested.setName("nested");
        nested.setTypeAsDataSource(DataSource.get("SimpleNestedObject"));
        DataSourceField outerA = new DataSourceField("outerA", FieldType.Float);
        DataSourceField outerB = new DataSourceField("outerB", FieldType.Float);
        setFields(nested, outerA, outerB);
        return this;
       }
      }.init());
      FormItem innerA = new FormItem("a");
      innerA.setDataPath("nested/a");
      FormItem innerB = new FormItem("b");
      innerB.setDataPath("nested/b");
      FormItem c = new FormItem("c");
      c.setDataPath("nested/c");
      FormItem outerA = new FormItem("outerA");
      FormItem outerB = new FormItem("outerB");
      form.setFields(innerA, innerB, c, outerA, outerB);
     }
    
     public void setNested(Record nested) {
      form.setValue("nested", nested);
      //to get nested values to update
      for(FormItem field : form.getFields()) {
       field.redraw();
      }
     }
    
     public void setOuter(double a, double b) {
      form.setValue("outerA", a);
      form.setValue("outerB", b);
     }
    }
    Last edited by jpappalardo; 1 Dec 2014, 14:30.

    #2
    First, make sure you understand that the dataPath feature is there to accommodate certain legacy data architectures that are "denormalized" (in the database theory sense). Generally we would recommend that you do not use the dataPath feature unless you are trying to work around a legacy architecture that you can't correct in any other way.

    Second, this code sample looks like it's possibly pseudocode or relies on code you haven't shown (the "inialize" call jumps out, for instance). Have you reproduced this problem in a standalone test case?

    Comment


      #3
      Sorry I edited the code to call the init() method of the DataSource. This code is generally speaking a duplicate of the code that I am using, I just changed fields and what not to obscure our actual data.

      Is there another way in which we should be handling Embeddable objects in our DataBase? I was unable to discern another method that would effectively encapsulate them using your DataSources. And so if you consider the nested object to be an Embeddable JPA element, and the client side ds is reusing that Embeddable datasource, at present this is not a server side ds but is headed in that direction and will need to use the Embeddable object server side.

      Comment


        #4
        Embeddables are indeed an example of denormalization, and as such, normally something you'd do for performance reasons.

        Without getting into a discussion of how you decided to use Embeddables in the first place, have you considered just using dataSourceField.valueXPath so that the nested structure is never exposed to the client side at all? Certainly, if it's an artifact of some kind of server-side optimization, then it isn't needed client-side.

        Comment


          #5
          So is that to say what I am doing is not supported, and I am required to manually refresh any fields that contain nested data structures?

          Comment


            #6
            No, we're checking on whether this behavior is expected to be automatic or not, however what we're pointing out is that you probably don't want to use this approach at all.

            Comment


              #7
              Actually, on review, we would not expect this behavior to be automatic.

              The contract of setValue() is that it will update FormItems that are bound to specific field names, and store arbitrary values which are not associated with FormItems.

              There is no FormItem with the name "nested", so no update would be expected here.

              Basically, this is another oddness in your usage - you've set up FormItems to deal with individual fields from a nested object, so that everything appears "flattened". But then your style of updating is to replace a whole sub-object. We'd recommend picking one style or another:

              1. really flatten things, so that the nested structure, which appears to be a server-side implementation detail, is never seen client-side (using valueXPath as previously indicated)

              OR

              2. really treat things as a distinct structure, by using a separate DataSource linked by foreignKey, not a nested DataSource.

              Comment

              Working...
              X