Bindings in Open Swing

Kamal
2012-05-07
2013-04-25
  • Kamal
    Kamal
    2012-05-07

    I want to understand the limitations (if any) of bindings used in OpenSwing as compared to JGoodies or BeansBindings. For example, with BeansBindings you can bind a control's properties to an appropriate property on a class with observable properties (i.e. a bean). To be specific, you can bind JTextField's "text" properties to a String property "xxx" of a class that makes the "xxx" property observable (it publishes propertychanged events when the property changes when it's setter is called). BeansBindings allows this binding to be two-way so that the control property updates when the beans property updates and vice versa. This also means that the binding property mapping between control containers and beans is n-n. For example, controls in a form can bind to properties on multiple beans. Similarly, the properties on a bean can be bound to controls in multiple forms.

    In OpenSwing, the container class (limited to Form, I think) allows specifying the top-level value object (acts as a bean but doesn't need the properties to be observable) and then each control in the Form can bind by setting its "attribute" property to a property (or sub-property if the value object has internal objects) on the value object. The Form has pull, push functions that move the data to and from the Form. When the from is in Edit mode, I can see that making changes to the controls triggers the property setters of the bound "attribute" of the value object. However, unlike BeansBindings, text fields push updates only when "enter" is pressed (and I presume when focus is lost) but not while typing. Also, it's not clear to me how   other components in an application can "push" a change to the Form without reloading the whole Form. In BeansBinding, just calling the setter of the bean property bound to the control will trigger only the control display to update. Also, binding properties accessible to the controls in a Form are limited to the value object and whatever is accessible through it - only a single value object can be used with a Form so it is a 1-1 relationship between the container class (Form) and the bean (value object).

    The problem I am trying to solve is for editing changes made in one Form to automatically trigger updates in another Form without having to overtly call a reload of the entire form. These updates are transient. The persistent data model is not affected unless the use saves the Form. Any pointers will be appreciated.

     
  • Kamal
    Kamal
    2012-05-08

    I realize that this might be the wrong forum for this. I apologize in advance but will be cross-posting to a more appropriate forum.

     
  • mcarniel
    mcarniel
    2013-04-25

    Hi!

    You can also access to the Model part of the Form, through the Form.getVOModel() method.
    This allows you to access to VOModel which provides you several useful methods to work with.
    For instance, you can use VOModel.setValue() method to set specific values directly to the linked value objects, by specifying the attribute to set.

    Moreover, you can also set the whole value objecy, through VOModel.setValueObject method, (if you need to set the content of another Form...) and then use Form.push() method to sync the value object to the binded controls.