Chapter 10. Rich inputs

10.1. <rich:autocomplete>
10.1.1. Basic usage
10.1.2. Submission modes
10.1.3. Interactivity options
10.1.4. Customizing the filter in client and lazyClient modes
10.1.5. JavaScript API
10.1.6. Reference data
10.1.7. Style classes and skin parameters
10.2. <rich:calendar>
10.2.1. Basic usage
10.2.2. Behavior and appearance
10.2.3. Time of day
10.2.4. Localization and formatting
10.2.5. Using a data model
10.2.6. Client-side customization
10.2.7. JavaScript API
10.2.8. Reference data
10.2.9. Style classes and skin parameters
10.3. <rich:editor>
10.3.1. Basic usage
10.3.2. Styling
10.3.3. Editor skins
10.3.4. Advanced configuration
10.3.5. Toolbar customization
10.3.6. Internationalization and localization
10.3.7. Client-side event handlers
10.3.8. JavaScript API
10.3.9. Reference data
10.3.10. Style classes and skin parameters
10.4. <rich:fileUpload>
10.4.1. Basic usage
10.4.2. Upload settings
10.4.3. Sanitizing file upload input
10.4.4. Interactivity options
10.4.5. <rich:fileUpload> client-side events
10.4.6. Reference data
10.4.7. Style classes and skin parameters
10.5. <rich:inplaceInput>
10.5.1. Basic usage
10.5.2. Interactivity options
10.5.3. JavaScript API
10.5.4. Reference data
10.5.5. Style classes and skin parameters
10.6. <rich:inplaceSelect>
10.6.1. Basic usage
10.6.2. Interactivity options
10.6.3. JavaScript API
10.6.4. Reference data
10.6.5. Style classes and skin parameters
10.7. <rich:inputNumberSlider>
10.7.1. Basic usage
10.7.2. Interactivity options
10.7.3. JavaScript API
10.7.4. Reference data
10.7.5. Style classes and skin parameters
10.8. <rich:inputNumberSpinner>
10.8.1. Basic usage
10.8.2. Interactivity options
10.8.3. JavaScript API
10.8.4. Reference data
10.8.5. Style classes and skin parameters
10.9. <rich:select>
10.9.1. Basic usage
10.9.2. Using manual input
10.9.3. Advanced options
10.9.4. JavaScript API
10.9.5. Reference data
10.9.6. Style classes and skin parameters
10.10. <rich:orderingList>
10.10.1. Basic usage
10.10.2. Column Layout
10.10.3. JavaScript API
10.10.4. Reference data
10.10.5. Style classes and skin parameters
10.11. <rich:pickList>
10.11.1. Basic usage
10.11.2. Column Layout
10.11.3. JavaScript API
10.11.4. Reference data
10.11.5. Style classes and skin parameters
This chapter details rich components for user input and interaction.

10.1. <rich:autocomplete>

The <rich:autocomplete> component is an auto-completing input-box with built-in Ajax capabilities. It supports client-side suggestions, browser-like selection, and customization of the look and feel.
The auto-complete box is a standard JSF UIInput control with added validation.
<rich:autocomplete>

Figure 10.1. <rich:autocomplete>

10.1.1. Basic usage

The value attribute stores the text entered by the user for the auto-complete box. Suggestions shown in the auto-complete list can be specified using one of two different methods:
  • The autocompleteMethod attribute points to a method which returns a list of suggestions according to a supplied prefix.

    Note

    The prefix is normally ignored in client and lazyClient modes. In these modes, the component requests the suggestion list once only, and performs filtering on the client.
  • The autocompleteList attribute points to a collection of suggestions.

Example 10.1. Defining suggestion values

Using the autocompleteMethod attribute
<rich:autocomplete value="#{bean.state}" autocompleteMethod="#{bean.autocomplete}" />
The <rich:autocomplete> component uses the bean.autocomplete method to provide suggestions, based on the entered prefix.
Using the autocompleteList attribute
<rich:autocomplete value="#{bean.state}" autocompleteList="#{bean.suggestions}" />
The <rich:autocomplete> component retrieve the suggestion list from bean.suggestions.

10.1.2. Submission modes

Use the mode attribute to determine how the suggestion list is requested:
  • The client setting pre-loads data to the client and uses the input to filter the possible suggestions.
  • The ajax setting fetches suggestions with every input change using Ajax requests.
  • The lazyClient setting pre-loads data to the client and uses the input to filter the possible suggestions. The filtering does not start until the input length matches a minimum value. Set the minimum value with the minChars attribute.
  • The cachedAjax setting pre-loads data via Ajax requests when the input length matches a minimum value. Set the minimum value with the minChars attribute. All suggestions are handled on the client until the input prefix is changed, at which point a new request is made based on the new input prefix.

10.1.3. Interactivity options

Users can type into the text field to enter a value, which also searches through the suggestion items in the drop-down box. By default, the first suggestion item is selected as the user types. This behavior can be deactivated by setting selectFirst="false".
Setting autofill="true" causes the <rich:autocomplete> to fill the text field box with a matching suggestion as the user types.
To allow users to enter multiple values separated by specific characters, use the tokens attribute. As the user types, a suggestion will present as normal. When they enter a character specified as a token, this begins a new suggestion process, and the component only uses text entered after the token character for suggestions. For example, if tokens=", " is set, the <rich:autocomplete> component uses both the comma and space characters as tokens to separate entries. When the user enters a comma or a space, a new suggestion process begins.

Note

When declaring tokens, avoid using any characters that are present in the list of suggestions. This may cause unexpected behavior as the user expects the character to match suggestions instead of separating suggested entries.

10.1.4. Customizing the filter in client and lazyClient modes

The <rich:autocomplete> component uses the JavaScript startsWith() method to create the list of suggestions. The filtering is performed on the client side. Alternatively, use the clientFilterFunction attribute to specify a custom filtering function. The custom function must accept two parameters: the subString parameter is the filtering value as typed into the text box by the user, and the value parameter is an item in the list of suggestions against which the subString must be checked. Each item is iterated through and passed to the function as the value parameter. The custom function must return a boolean value indicating whether the passed item meets the conditions of the filter, and the suggestion list is constructed from successful items.

Example 10.2. Customizing the filter

This example demonstrates how to use a custom filter with the clientFilterFunction attribute. The custom filter determines if the sub-string is contained anywhere in the suggestion item, instead of just at the start.
<script>
   function customFilter(subString, value){
      if(subString.length>=1) {
         if(value.indexOf(subString)!=-1) 
            return true;
      }else return false;
   };
</script>
<h:form>
   <rich:autocomplete mode="client" minChars="0" autofill="false"
                      clientFilterFunction="customFilter"
                      autocompleteMethod="#{autocompleteBean.autocomplete}" />
</h:form>

10.1.5. JavaScript API

The <rich:autocomplete> component can be controlled through the JavaScript API. The JavaScript API provides the following functions:
getValue()
Get the current value of the text field.
setValue(newValue)
Set the value of the text field to the newValue string passed as a parameter.
showPopup()
Show the pop-up list of completion values.
hidePopup()
Hide the pop-up list.

10.1.6. Reference data

  • component-type: org.richfaces.Autocomplete
  • component-class: org.richfaces.component.UIAutocomplete
  • component-family: javax.faces.Input
  • renderer-type: org.richfaces.AutocompleteRenderer
  • handler-class: org.richfaces.view.facelets.AutocompleteHandler

10.1.7. Style classes and skin parameters

Table 10.1. Style classes (selectors) and corresponding skin parameters

Class (selector) Skin Parameters Mapped CSS properties
.rf-au-fnt
This class defines styles for the auto-complete box font.
generalTextColor
color
generalFamilyFont
font-family
generalSizeFont
font-size
.rf-au-inp
This class defines styles for the auto-complete input box.
controlBackgroundColor
background-color
.rf-au-fld
This class defines styles for the auto-complete field.
panelBorderColor
border-color
controlBackgroundColor
background-color
.rf-au-fld-btn
This class defines styles for a button in the auto-complete field.
No skin parameters.
.rf-au-btn
This class defines styles for the auto-complete box button.
headerBackgroundColor
background-color
panelBorderColor
border-left-color
.rf-au-btn-arrow
This class defines styles for the button arrow.
No skin parameters.
.rf-au-btn-arrow-dis
This class defines styles for the button arrow when it is disabled.
No skin parameters.
.rf-au-lst-scrl
This class defines styles for the scrollbar in the auto-complete list.
No skin parameters.
.rf-au-itm
This class defines styles for an item in the auto-complete list.
No skin parameters.
.rf-au-itm-sel
This class defines styles for a selected item in the auto-complete list.
headerBackgroundColor
background-color
generalTextColor
border-color
.rf-au-shdw
This class defines styles for the auto-complete box shadow.
No skin parameters.
.rf-au-shdw-t, .rf-au-shdw-l, .rf-au-shdw-r, .rf-au-shdw-b
These classes define styles for the top, left, right, and bottom part of the auto-complete box shadow.
No skin parameters.
.rf-au-tbl
This class defines styles for a table in the auto-complete box.
No skin parameters.