Binding data model context

To easiest the readability and maintainability of the code, and to shorten in XPath paths, some components can works as a relative xpath context for the contained ZK components. When a container type object is associated with a data model element, binds on child components that do not specify a data source are understood as parent container relative XPaths.

The components that can act as context data model implement the es.caib.zkib.BindContext interface. Currently, grid, lisbox, row and form components. Due to implementation constraints, the listiem object does not implement the aforementioned interface.

The simplest of those components is the Form object (which derives from Vbox). For context associations, the attribute to be used is called datapath, as shown in the following example:

<?xml version = "1.0" encoding = "UTF-8">
<zk>
    <xmlDataSource id = "mydata" src = "/ my-data.xml" />
    <form dataPath = "/mydata:/title">
        <label bind = "/@name" />
        <textbox bind = "/@name" />
        <button label = "Update" />
     </form>
</zk>

In this example, both the object label, as the textbox object refer to the same attribute @name, which is relative to the context /mydate:/title. When the user changes the textboxitem, the same text will be shown on the label. Mind the synchronization will only be done when the data is sent to the server, by means of any ZK event. In order to make user interface to be more responsive, simply add an onChange or onChanging null handler to the textbox component.

<?xml version = "1.0" encoding = "UTF-8">
<zk>
    <xmlDataSource id = "mydata" src = "/ my-data.xml" />
    <form dataPath = "/mydata:/title">
        <label bind = "/@name" />
        <textbox bind = "/@name" onChanging=""/>
        <button label = "Update" />
     </form>
</zk>

 


Revision #2
Created 1 June 2021 10:06:55 by pgarcia@soffid.com
Updated 1 June 2021 10:13:11 by pgarcia@soffid.com