Accessing the Data

The Field object has a Binding property that defines the source path and target path that identify the data that is bound to the field. These paths combine the server interface name and the property name into a single value. The context provides a DataAccessor object that can be invoked to resolve paths to their values. For a view-renderer, only the source path is provided. The target path is only provided for edit-renderers (presented in A Text Field Widget with No Auto-completion). Paths can represent values other than server interface properties. The developer should not be concerned about where the data comes from, only that it can be retrieved when required. More information about the available paths and their forms is provided in Accessing Data with Paths. The code to retrieve the e-mail address string value is shown below.

Figure 1. Getting the E-Mail Address Value
String emailAddress = context.getDataAccessor()
       .get(field.getBinding().getSourcePath());

The source path is retrieved from the field's binding and passed to the get method of the data accessor retrieved from the context. The source path will never be null for a view-renderer plug-in. The get method will return the value of the (in this case) server interface property. The value will be formatted to a string representation appropriate for the active user. This formatting is performed using the format method of the DomainConverter plug-in associated with the domain of the server interface property. While the formatting of an e-mail address value is trivial (the value is simply returned as is), other values, such as dates and date-times must be formatted using the active user's locale, time zone and date format. Regardless of the type of the underlying data, this will all be handled automatically by the converter plug-ins. The returned string will be suitable for inclusion in the HTML response without any further formatting. See the Cúram Web Client Reference Manual for more information on converter plug-ins and their format methods.