6 Replies Latest reply on Sep 4, 2014 3:06 PM by Slava Pankov

    Errai databinding - nested binding

    Slava Pankov Newbie

      I'm not sure how properly formulate my question, perhaps example is the best way to do that:



      class MyNestedEntity {

          String getA();

          void setA(String value);

          String getB();

          void setB(String value);




      class MyModel {

          MyNestedEntity getData();

          void setData(MyNestedEntity value);



      UI is bound to model as "data.a" and "data.b"

      And now let's say I'm trying to change data property to another entity, like this:

      MyNestedEntity newEntity = new MyNestedEntity();


      UI is not updated. To make it working, I have to add additional method to my model:

      void setNewData(MyNestedEntity value) { this.data = value; }

      and use model.setNewData(newEntity) when I want to replace nested data.


      Not a big deal, but the question is - why? It looks kind of strange and additional code is not actually needed.

      The root of this behavior is lying in BindableProxyAgent.updateWidgetsAndFireEvents() implementation.

      nestedBinder.setModel() is called only in case of parameterless method, but for some reason is not called by updateWidgetsAndFireEvent(String property, P oldValue, P newValue);

      Is there any reason for for such design? Or it's just a bug?

      If nestedBinder.setModel() logic is added to second method, then setNewData(...) won't be needed anymore in my model, and code will be more straightforward.