|
introduction get started articles manual tutorials reference docs case studies knowledge base goodies screenshots demos echoes Carousel zone home forums downloads bugs mailing list |
XUI Zone - knowledge base
Using library functions to bind components to the model In this example we are going to show how the basic XUI databinding can include a reference to a library function. This provides a very effective way of separating common functionality in your application and in the process giving you an easy to configure plugin structure. We can begin by creating the data which will be bound to our pages. This example will show how to switch unit sets for engineering calculations but this could just as easily be applied to currencies. The data we will be binding is shown in Listing 1.
Listing 1 - The static data for the application
As you can see there are two sets of units from which the user will be able to select their preference. Now we will create the welcome page as shown in Listing 2 where the unit set will be selected.
Listing 2 - The Welcome page
The ComboBox is bound to the units/sets XModel node and the button, when clicked, will call the proceed method in the net.xoetrope.libtest.Welcome class which is shown in Listing 3.
Listing 3 - The Welcome class
The unitspage in Listing 4 is displayed.
Listing 4 - The unitspage
This page includes three labels which are bound to the a library class in the data binding node declarations. The first binding uses the syntax ${net.xoetrope.units.UnitHandler[unitlib].getSelectedUnit()} to call the getSelectedUnit function in the library class and subsequent calls can use the syntax ${[unitlib].getSelectedUnit()} as unitlib is the name under which the library instance is stored by XUI. Now we can take a look at the library function in Listing 5 .
Listing 5 - The UnitHandler library function class
The ComboBox outputs its selected value to the xui_state/units/sets Model node and it is access in order to discover its value. Next the sets are iterated and compared to the selected one. When found the ID of the selected set is returned meaning that the components will effectively be bound to units/SI/power where SI replaces ${[unitlib].getSelectedUnit()} in the model path. The running application can be seen in the screenshot below. comments If you were logged in you could rate this article or add a comment. |