BeeSoft®
Since 1992
 

Content

 Welcome
 Products
       Abeona
       Gaia
             News
             Documentation
                   Introduction
                   Swing support
                         Components
                         Building from XML
                               Step by step
                               XML elements
                               Data binding
                               Internationalization
                         Client / server
                   Server application
                   Validation
                   XML
                   Logging
                   Utilities
                   Launcher
             License
             Download
       Hephaistos
       JavaGantt
 Services
       Promote your software
 Contact Us
 Links
      
  GaiaI®
© 2012 BeeSoft ®
 

Data binding

Data binding assumes that there is one root data object for displayed form. Another objects are referenced from it or from objects referenced by it. So the object hierarchy is requested in bound data.

The binding for builder (and its object / component) is recorded in source XML file with the attribute 'binding'. You can use also so called dot-convention: if your object references an object A via property a, the object A references an object B via property b, and you want to display property c of object B, you can write binding as a.b.c - it is easy.

The binding corresponds to the element hierarchy. If element A has set binding="a" and element A has sub-element B and this has set binding="b", then the qualified binding in the element B is a.b and this is the path how is find data value from root data objet for a component created from the element B.

This algorithm is used to bind a specific data property to component created by the builder:

  1. it is looking for getter / setter
  2. tries a field access
  3. if property container is an instance of eu.beesoft.gaia.util.ValueObject, it uses its get / set method
  4. throws exception if property is not accessible

Of course, binding is working in two ways: you can initialize created components from data objects and you can also update data objects by components.

From a programmer point of view, only a few lines of code is necessary to implement data binding:

	// prepare path to form XML 
	String formId = "mypackage/myform.form";

	// prepare resource bundle name
	String messagesId = "mypackage.myform";

	// create new builder factory
	SwingBuilderFactory factory = new SwingBuilderFactory ();
	factory.setResourceBundle (messagesId);

	// build component (form, menu, application, ...)
	InputStream is = Streams.getInputStream (formId);
	ComponentBuilder<?> builder = (ComponentBuilder<?>) factory.build (is);

	// bind data object with Swing components
	// note: root data object can reference other data objects
	Object data = ...
	builder.setBoundData (data, null);

	// display form
	Component component = builder.getObject();
	myFrame.getContentPane().add (component);

	// process user input
	...

	// create collection to keep changed data objects
	// this collection will be filled in the next method
	Set changedObjects = new HashSet<Object> ();

	// get (modified) data from builders
	// returns root data object
	Object data = builder.getBoundData (changedObjects,null);