Variables and Binding

As you build your page, you are going to want to tie specific components, such as widgets, to data objects in your application. For example, you might want to tie a DataGrid widget to a table in a database or you might want to set up an Editor widget to display a result string from a Web service.

To set up a data source for a component, you first need to create a Variable (see Variables, LiveVariables and Service Variables below) and then bind your component to that Variable (Bindings).

Variables LiveVariables and Service Variables

Your WaveMaker project can include the following types of variables:

  • Variables: A generic variable that can store data on the page or at the project level.
  • LiveVariables are special variables that store an instance of a LiveTable or a LiveView. Controls like LiveForm require a LiveVariable as input. See Creating LiveVariables for more information.
  • Service Variables: This type of variable contains configuration for calling a service and storing the results of that call. See Creating a Service Variable for more information.
  • Logout Variables: Specialized variable used to logout of the application. Must be used in concert with Security (See Authentication).

Creating LiveVariables

LiveVariables are special variables that stores the results of a query to a LiveTable or a LiveView. Controls like LiveForm require a LiveVariable as input. Use a LiveVariable to access a LiveTable or a LiveView. LiveVariables, LiveTables and LiveViews are all part of WaveMaker Studio's LiveData feature.

LiveData is a term for WaveMaker Studio's special set of controls and data objects that let you quickly and easily create database-driven application elements. For example, you get auto-generated Insert/Delete/Update functionality with LiveData.

There are two ways to create a LiveVariable:

  1. Select the Insert menu then choose LiveVariable.
  2. From the Palette, expand the Non-Visual Components then drag LiveVariable onto your page.
The properties for the new LiveVariable are displayed in the Property Editor. The LiveVariable's properties are listed in the table below.
PropertyDescription
nameThe name that WaveMaker Studio uses to reference the widget. This is the name that appears in Model Tree, in the Page Builder, in Binding dialogs, and so on; this is also the name you use to reference the widget in code services.
ownerVariables are owned by the Application and shared among many pages or owned by a Page and only accessible from the owning page.
autoUpdateThe component runs automatically. Enables LiveLayout to populate the data directly in the WaveMaker Studio.
startUpdateThe component is initialized when the page is initially loaded.
operationA menu containing the database operations that are available for the LiveVariable (read, insert, update and delete).
liveSourceThis menu contains all objects that you can use for the LiveVariable source (LiveTables and LiveViews).
sourceDataThe meaning of this property changes based on the LiveVariable's operation:
For "readData," sourceData specifies a root object for which we are gathering more data. This is useful for getting additional related objects for a given object. For example, if a liveVariable is setup to retrieve Customers with Addresses, then by default it returns a list of all Customers, each with the Address related object. However, if sourceData has been set to an existing Customer object, say retrieved by another liveVariable, then the liveVariable will return that Customer with that Address related object.
For the other operations, sourceData specifies the data that will be saved on the server (inserted, updated, or deleted).
filterYou can filter your live source by setting the filter property. You can set up filters on individual fields by selecting the filter object in the Properties Tree.
matchModeDetermines how to match string values. matchMode can be one of the following values: "anywhere", "start", "end", "exact". Default: start.
firstRowfirstRow is useful for setting up paging and works in conjunction with maxResults. firstRow is ignored if maxResults is not set. If a result set has 100 rows and you set maxResults to 10 and firstRow to 11, then you'll get rows 11-20.
maxResultsThe number of records that will be returned at runtime.
designMaxResultsThe number of records that will be returned when viewing data at design time.
orderBySpecify a property to use for ordering the data. You can order in ascending or descending order:
asc: propertyName
or
desc: propertyName
For example:
asc: actorId
desc: item.company
ignoreCaseChoose whether to make the results case sensitive or not.
updateNowUse to update the LiveVariable (with new input data) while in design mode.
queueDefines a list of Variables to execute, in order, after this LiveVariable executes.
clearInputClears all current input values.

See Also: LiveVariable.

Bindings

In WaveMaker Studio, the connection between a component (or component property) and a source of data, is called the binding. In order to set up a binding, you need to:

  1. Import the data model (Importing a Data Model), web service (Web Services), or Java service (Java Services) that you want to access.
  2. Create a Variable or a LiveVariable that will access the service and store the results of the service call. The difference between a Variable and a LiveVariable is that a LiveVariable must be based on a LiveTable or a LiveView. You should use a LiveVariable rather than a Variable where possible, because LiveVariables give you access to LiveData features (Live Data).
  3. Bind the widget to the variable you created. You typically bind LiveForm and DataGrid widgets and these two widgets have a dataSet property for easy binding. The dataSet property gives you a drop-down menu of valid data sources. The more generic way to bind any component to any data source is with the binding dialog (More on Binding).

More on Binding

To bind components to data, you use the binding dialog. In the Property Editor, anything that you can bind to is marked with the circular "bind" icon.

BindIcon.png

When you click the Bind icon, the Binding dialog appears. Across the top of the data binding dialog, there are three radio buttons that allow you to specify how you want to set up the data source for the operation input.

BindDialog.png

The choices are:

  • Simple: This provides you a list of objects that you would most commonly bind to, such as the currently selected item in a DataGrid, the properties of an Editor widget and so on.
  • Advanced: This is a list of everything that you can bind to, including all Variables, Widgets and so on. Note that you can bind to components that are defined on the current page or that are defined at the project level. Components defined on other pages do not appear in this list.
  • Resources: This is a list of resources included in the project.
  • Expression: This can be any JavaScript expression. You can refer to widgets in the page using their name properties. See Customizing with JavaScript for details on how to do this. Also see Binding Expressions.
Note: By default expressions are considered strings. To have an expression evaluated as a number, begin it with %% (two percent signs). For example %%1 will be evaluated as the number 1.

When you have selected the appropriate data source, click the Bind button. This sets up the data source for the selected object. A link icon now replaces the circular bind icon, showing that the object is bound to a data source.

BindingIcons.png

To delete the binding, click the "delete" (X) icon. You can view the binding in the Bind dialog by clicking the link icon.

Bind to displayValue or dataValue

In the Binding dialogs, you can choose bind to an editor's displayValue or its dataValue. In many cases displayValue and dataValue are the same. They are different for widgets that display a value differently from the way it is stored in the underlying data.

The most common case in which the two values are different is for dates and times: displayValue is the readable string (1/02/08) whereas the dataValue is the date in milliseconds that is expected by a service.

It is usually best practice to bind to the dataValue. However, when you are binding to another UI element, such as a label, you sometimes need to bind to the displayValue. Setting either the displayValue or dataValue updates the other property.

See Also


      Share/Bookmark
© 2010 WaveMaker Software™ All Rights Reserved.