10.6. <rich:inplaceSelect>
The
<rich:inplaceSelect> component is similar to the <rich:inplaceInput> component, except that the <rich:inplaceSelect> component uses a drop-down selection box to enter text instead of a regular text field. Changes can be rendered either in-line or for the whole block, and inputs can be focused with keyboard navigation. The component is based on the JSF UISelectOne component, so all the standard rules for value definition, processing, conversion, and validation apply.
The component has three functional states:
- When in the view state, the component displays its initial setting, such as "click to edit".
- When in the edit state, the user can select a value from a drop-down list.
- When in the changed state, the new value for the component has been confirmed, but it can be edited again if required.
10.6.1. Basic usage
Basic usage requires the
value attribute to point to the expression for the current value of the component and a list of items. The list of items can be defined using the JSF components <f:selectItem/> and <f:selectItems/>.
Example 10.8. Defining list items for <rich:inplaceSelect>
<rich:inplaceSelect value="#{bean.inputValue}" defaultLabel="click to edit" > <f:selectItems value="#{bean.selectItems}" /> <f.selectItem itemValue="1" itemLabel="Item 1" /> <f.selectItem itemValue="2" itemLabel="Item 2" /> <f.selectItem itemValue="3" itemLabel="Item 3" /> <f.selectItem itemValue="4" itemLabel="Item 4" /> </rich:inplaceSelect>
10.6.2. Interactivity options
When in the initial view state, the starting label can be set using the
defaultLabel attribute, such as defaultLabel="click to edit". Alternatively, if the initial value is already set through the value attribute, this is displayed instead.
By default, the event to switch the component to the edit state is a single mouse click. This can be changed using the
editEvent attribute to specify a different event. When switching to edit mode, the drop-down list of possible values will automatically be displayed; this can be deactivated by setting openOnEdit="false".
Once a new value for the control is saved, the state switches to the "changed" state. Saving a new value for the control can be performed in a number of ways:
- Once the user selects an item from the drop-down list, the item is saved as the new control value. This is the default setting. If
saveOnSelect="false"is set, the component applies the selected item but remains in the edit state so a different selection could be chosen. The value is then applied when the Enter key is pressed. - If
saveOnBlur="true"is set, the selected item is saved as the new control value when the control loses focus. - If
showControls="true"is set, buttons are added to the control to confirm or cancel the selection. The new control value is only saved once the user confirms the selection using the button.
Pressing the Esc key cancels editing in all cases.
10.6.3. JavaScript API
The
<rich:inplaceSelect> component can be controlled through the JavaScript API. The JavaScript API provides the following functions:
getValue()- Get the current value of the select control.
setValue(newValue)- Set the value of the select control to the
newValuestring passed as a parameter. isEditState()- Returns
trueif the control is currently in the edit state, orfalseif the control is currently in the view state. isValueChanged()- Returns
trueif the control's value has been changed from the default. save()- Saves the current item as the control's value.
cancel()- Cancel editing the value.
getInput()- Return the input entered into the control by the user.
getLabel()- Return the default label of the control.
setLabel(newLabel)- Set the default label of the control to the
newLabelstring passed as a parameter. showPopup()- Show the pop-up list of possible values.
hidePopup()- Hide the pop-up list.
10.6.4. Reference data
component-type:org.richfaces.InplaceSelectcomponent-class:org.richfaces.component.UIInplaceSelectcomponent-family:org.richfaces.Selectrenderer-type:org.richfaces.InplaceSelectRenderer
10.6.5. Style classes and skin parameters
Table 10.6. Style classes (selectors) and corresponding skin parameters
| Class (selector) | Skin Parameters | Mapped CSS properties |
|---|---|---|
| editorBackgroundColor
|
background-color
|
generalTextColor
|
border-bottom-color
| |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| editBackgroundColor
|
background
|
generalTextColor
|
color
| |
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| generalTextColor
|
border-color
|
| generalTextColor
|
border-color
|
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| tabBackgroundColor
|
background-color
|
panelBorderColor
|
border-color
| |
| tabBackgroundColor
|
background-color
|
panelBorderColor
|
border-color
| |
| No skin parameters. | |
| No skin parameters. | |
| editBackgroundColor
|
background-color
|
panelBorderColor
|
border-color
| |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
