Binding is a powerful feature of connecting a data entity with a GUI component. It saves you a lot of 'plumbing' work and keeps your code clean, while on the other side it helps your team write graphical client code in a standardized way.
The following example illustrates the process of binding a data field to a series of components:
Note: BoundLabel and BoundTextField are specifically (Java Swing) components, which are not part of the Sopity runtime library. Depending on your GUI framework (like JSF, GWT, Echo etc.), similar approaches may apply.
Please note that both the label and the text field are bound to the same Soplet, which provides all necessary meta information. In the case of the label, the text to display (according to the current language settings), and in the case of the textfield, the datasource and other information related to the loading and saving the data.
As the binding interface may define standard life cycle methods for all types of components (text field, combo, lists, tables etc.), the components can be easily iterated in the visitor pattern fashion:
Similar to the loading of values from the data object to the component, the user input can be saved back to the data layer:
Note that the save() operation may throw a ValidationException - this happens when the user enters an invalid value as defined by the corresponding Soplet. For example, in the case of the customer field, a warning is displayed when the field does not have any value, as this field has been marked as mandatory:
Note: For more sophisticated input validators please visit the Validators section