- What Is Dojo?
- Default Dojo Libraries Using Dojo Modules in XPages
- Dojo Modules and Dojo in the Extension Library
- Dojo Extensions to the Edit Box Control
- Dojo Extensions to the Multiline Edit Box Control
- Dojo Extensions to the Select Control
- Dojo Extensions to Buttons
- Composite Dojo Extensions
- Dojo Effects Simple Actions
- Conclusion
Dojo Extensions to the Select Control
As with the other input controls, the Dojo modules for selecting values have been included in the Extension Library. Besides the Dojo Radio Button (xe:djRadioButton) and Dojo Check Box (xe:djCheckBox) controls, there are two Dojo versions of the core Combo Box control: the Dojo Combo Box (xe:djComboBox) and Dojo Filtering Select (xe:djFilteringSelect).
The core Combo Box control is good for ensuring that users select from a restricted list of options, but it does not allow type-ahead. The Edit Box control offers this kind of type-ahead functionality, but it does not force the user to select one of the options provided. The benefit of the Dojo Combo Box and Dojo Filtering Select controls in the Extension Library is that they combine the type-ahead and restrict the user to just the options available. The sole difference between the two is that the Dojo Combo Box control holds a list only of values, whereas the Dojo Filtering Select control holds a list of label/value pairs.
Dojo Combo Box and Dojo Filtering Select (xe:djComboBox and xe:djFilteringSelect)
Developers who are more familior with dojo.data stores such as the ItemFileReadStore can take advantage of the store property and reference a JavaScript store. This is just a JSON object returning a collection of items that could be returned by an XAgent or some other API to return a JSON object. However, if the source data has been provided by a third party, it might not return a name attribute for the Dojo Combo Box to search. In this situation, the searchAttr property can be used to specify a different attribute in the JSON object on which to search. By default, any search, whether against defined items or against a dojo.data store, is case insensitive, but you can enforce case sensitivity by setting the ignoreCase property to true.
By default, whether querying a coded list of options or a dojo.data store, a starts with query will be performed. That is, the only results returned will be those that start with the letter or letters. Sometimes developers might prefer to query the store differently; Dojo provides this functionality. There are three expressions to be used for starts with searches, contains searches, and exact match searches. However, the expressions use the phrase "${", which has a specific meaning to the XSP Command Manager, so the easiest method of entering the expressions is using Server-Side JavaScript. The three variants are included in Listing 5.7, Listing 5.8, and Listing 5.9.
Listing 5.7. Contains Search Expression
<xe:djComboBox id="djComboBox2" value="#{sessionScope.djComboBox1}" tooltipPosition="before" title="This is a comboBox" pageSize="2"> <xe:this.queryExpr><![CDATA[${javascript:"*$\{0}*"}]]></xe:this.queryEx pr> <xp:selectItem itemLabel="Ford" itemValue="ford"> </xp:selectItem> <xp:selectItem itemLabel="Toyota" itemValue="toyota"> </xp:selectItem> <xp:selectItem itemLabel="Renault" itemValue="renault"> </xp:selectItem> <xp:selectItem itemLabel="Mercedes" itemValue="mercedes"> </xp:selectItem> </xe:djComboBox>
Listing 5.8. Exact Match Search Expression
<xe:djComboBox id="djComboBox2" value="#{sessionScope.djComboBox1}" tooltipPosition="before" title="This is a comboBox" pageSize="2"> <xe:this.queryExpr><![CDATA[${javascript:"$\{0}"}]]></xe:this.queryExpr > <xp:selectItem itemLabel="Ford" itemValue="ford"> </xp:selectItem> <xp:selectItem itemLabel="Toyota" itemValue="toyota"> </xp:selectItem> <xp:selectItem itemLabel="Renault" itemValue="renault"> </xp:selectItem> <xp:selectItem itemLabel="Mercedes" itemValue="mercedes"> </xp:selectItem> </xe:djComboBox>
Listing 5.9. Starts with Search Expression
<xe:djComboBox id="djComboBox2" value="#{sessionScope.djComboBox1}" tooltipPosition="before" title="This is a comboBox" pageSize="2"> <xe:this.queryExpr><![CDATA[${javascript:"*$\{0}"}]]></xe:this.queryExp r> <xp:selectItem itemLabel="Ford" itemValue="ford"> </xp:selectItem> <xp:selectItem itemLabel="Toyota" itemValue="toyota"> </xp:selectItem> <xp:selectItem itemLabel="Renault" itemValue="renault"> </xp:selectItem> <xp:selectItem itemLabel="Mercedes" itemValue="mercedes"> </xp:selectItem> </xe:djComboBox>
To ease selection, a number of properties are available. The pageSize property allows you to define some entries that the drop-down box should show. If the query returns more entries, a link is added to allow the user to page down and page up through the available options, as shown in Figure 5.12 and Figure 5.13. This property doesn’t enhance performance by minimizing the number of options delivered to the browser, but you can use it to enhance presentation. As with the Dojo Number Spinner control, it is also possible to manage the response to the selection. In this case, the searchDelay property allows you to set the number of milliseconds delay before matching results are returned.
Figure 5.12. More choices on Dojo Combo Box.
Figure 5.13. Previous choices on Dojo Combo Box.
Because the Dojo Filtering Select uses label/value pairs and the Dojo Combo Box uses just a list of values, Dojo Filtering Select takes advantage of two additional properties and an event to handle the labels displayed. The first is labelType. By default, the labels are treated as plain text, but by setting this property to html, the labels are treated as HTML. The second is labelAttr, applicable for developers using a datastore. As with the searchAttr property, you can use this with a Dojo datastore to tell the Dojo Filtering Select to display labels from the store based on an attribute other than name. This does not affect the attribute from the store that is used to search on as the user types. To do that, you need to define the searchAttr property as well. An additional event is available on the Dojo Filtering Select called labelFunc. This triggers on selection of a valid entry and can trigger either Client-Side or Server-Side JavaScript.
Chapter 11, “REST Services,” covers REST services and other data integration, so at this point only a brief example of this functionality is shown in Listing 5.10. Lines 1 to 22 cover the REST service. Note that the jsId defined for the service in line 3 is allocated to the djFilteringSelect in line 26. In line 27, the FilteringSelect shows a list of U.S. states using the labelAttr property, but searches on the two-character abbreviation using the searchAttr property. The results are limited to 10 per page using the pageSize property in line 29.
Listing 5.10. Dojo Filtering Select Using DataStore
1 <xe:restService 2 id="restService1" 3 jsId="stateStore"> 4 <xe:this.service> 5 <xe:viewItemFileService 6 viewName="AllStates" 7 defaultColumns="true" 8 dojoType="dojo.data.ItemFileReadStore" 9 count="400"> 10 <xe:this.columns> 11 <xe:restViewColumn 12 columnName="Name" 13 name="Name"> 14 </xe:restViewColumn> 15 <xe:restViewColumn 16 columnName="Key" 17 name="Key"> 18 </xe:restViewColumn> 19 </xe:this.columns> 20 </xe:viewItemFileService> 21 </xe:this.service> 22 </xe:restService> 23 <xe:djFilteringSelect 24 id="djComboBox3" 25 value="#{sessionScope.djComboBox2}" 26 store="stateStore" 27 labelAttr="Name" 28 searchAttr="Key" 29 pageSize="10"> 30 </xe:djFilteringSelect>
Table 5.9 details the noteworthy properties of the Dojo Combo Box and Dojo Filtering Select.
Table 5.9. xe:djComboBox and xe:djFilteringSelect Properties
Property |
Description |
hasArrow |
Defines whether a drop-down arrow appears beside the field, to show selections. |
ignoreCase |
Defines whether the search of the store is case-sensitive. |
queryExpr |
Defines a query for the way the store is searched, as a “starts with”, “contains”, or “exact match”. For terminology, see Listing 5.7, Listing 5.8, and Listing 5.9. |
searchAttr |
Defines the attribute in the Dojo datastore to search on; by default, it is name. |
searchDelay |
Defines the number of milliseconds to delay before beginning the search. |
pageSize |
Allows the developer to specify the number of entries to show on each page of the search results. |
store |
Allows the developer to define a Dojo datastore from which to take the options for the Dojo Combo Box or Dojo Filtering Select. |
labelAttr |
Defines the attribute in the Dojo datastore from which to retrieve the label. If no property is defined, the attribute in the searchAttr property is used. This property is available only for the Dojo Filtering Select. |
labelFunc |
Defines an event handler to be called when the label changes, returning the label to be displayed. This property is available only for the Dojo Filtering Select. |
labelType |
Defines whether the label is plain text or HTML. This property is available only for the Dojo Filtering Select. |
Dojo Check Box and Dojo Radio Button
The primary intention of the Dojo Check Box and Dojo Radio Button controls is to style the controls appropriate for other Dojo controls. Both controls support the same functionality as the core control versions, so you can assign them to a group with custom values defined. The main difference with the Radio Button Group or Check Box Group is that the core controls for groups display their options in a table within a fieldset. The Dojo Check Box and Dojo Radio Button controls display options inline. In addition to this standard functionality and similarity to the other Dojo controls, the Dojo Check Box and Dojo Radio Button are enabled for accessibility. So the title property and the WAI-related properties can be defined, as can any of the other Dojo controls.