Hitachi Vantara Pentaho Community Wiki
Child pages
  • Advanced Guide to MVC in Pentaho XUL Applications

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Data Binding and Component-state Events

It is the responsiblity responsibility of your Controller implementation to setup bindings between your XUL components and your data model (a POJO/Java Bean). What do we mean by "binding"? Binding is a way to associate bean properties so that when one changes, the other is kept in sync. Binding can be unidirectional or bidirectional, but we won't get into that here. We will assume that a binding is always bidirectional meaning when either side of the binding changes, the other will reflect the change. This is useful in UI applications because we can tie, say, a text box's value to a model bean String property.  Consider the snippet below of a controller's onLoad method.  Following the Foo theme, notice how you can create a binding between a model's name property and a XUL component's value property. 

Code Block
public class FooController extends AbstractXulEventHandler { 
	... 
	onLoad() { 
		bind(fooViewModell, "name", "nameTextbox", "value");
	}
	...
} 

Behind the scenes this bind method is retrieving a XulComponent by id "nameTextBox" and linking the name property of the model to the value property of the XulComponent instance.  Now let's say in addition to binding the name property to a text box we want to wire the enabled state of an OK button to a boolean bean property on the model.  We would just add another bind call that ties the two properties together, notice the "!" expression which does an in-flight negation of boolean value (very helpful with XulComponents which use disabled rather than enabled properties).

Code Block

	onLoad() {
		bind(fooViewModell, "name", "nameTextbox", "value");
		bind(fooViewModell, "okEnabled", "okButton", "!disabled");
	}



In the diagram you will see that the XulDom fires "events" to the FooController.  Events in this contex

 

...