|
|
Introduction tutorial - Initialising controls from the model - Populating page controls
SUMMARY
This step introduces another way of working with the XModel. Screen data can be prepopulate with data from a file making it easy to move data around and to consume and export it in a consistent and reliable manner
FURTHER READING Again, this concept is elaborated on in great detail throughout the Advanced Tutorial and the Carousel Tutorial. You have probably noticed by this point that we don't any values in the dropdown list for titles on the personal page. That's what we'll look at next along with some options on how it's possible to initialise text controls from the model. Open the personal page and amend the Data node with a single Bind node: Listing 1 - personal.xml
...
<Data>
<Bind target="titleList" source="/defaults/titleList"
output="/mortapp/customer/title" />
...
Setting the source for the titleList comboBox to defaults/titleList, populates the comboBox with data from the defaults dataset in the static_data.xml file. This file is specified as being a data source for the application in the datasource.xml file. Set the source for dobText to customer/dob. The dobText Edit component will be populated with data coming from the customer dataset. Listing 2 - personal.xml
...
<Bind target="dobText" source="/mortapp/customer/dob" />
...
The target attribute refers to the component being bound to. The source attribute is the path to the part model which contains the items which will populate the list. The output attribute is the path to the part of the model which will store the seleted item in the list. We now need to load the data which is being referred to by the binding. First create the statics.xml file which contains the following... Listing 3 - statics.xml
<Datasets>
<dataset id="defaults">
<list id="titleList">
<item value="Mr" id="1" />
<item value="Mrs" id="2" />
<item value="Miss" id="3" />
<item value="Dr" id="4" />
<item value="Fr" id="5" />
</list>
</dataset>
<dataset id="customer">
<data id="dob" value="01/01/1970" />
</dataset>
</Datasets>
Any amount of these data files can be loaded by the application by referring to them from a datasets file. The datasets file in this example is referenced by the datasource.xml file as listed below... Listing 4 - datasource.xml
<DataSources> <DataSource name="ListValues" filename="statics.xml" /> </DataSources> The application needs to load the datasets.xml file so an entry for the ModelData property needs to be inserted into the startup.properies file. Both the statics.xml and datasource.xml file need to be in the resources directory. Listing 5 - startup.properties
ModelData=datasource.xml Just to finish off this section we will initialise the Data of birth edit control on the personal page with the customer/dob node in the model. There is already a binding for this control within the page so simply by defining the data within the statics.xml will have the effect of initialising the control with the static data.
Run the run.bat file and the application will appear as in the screenshot.
Log in or register to download the source code for this step. |