6.54.  < rich:inplaceSelect >

6.54.1. Description

The <rich:inplaceSelect> is used for creation select based inputs: it shows the value as text in one state and enables editing the value, providing a list of options in another state

<rich:inplaceSelect> component

Figure 6.116.  <rich:inplaceSelect> component


6.54.2. Key Features

  • Option to display "save", "cancel" buttons as icons
  • Option to display "save", "cancel" buttons as standard buttons
  • Possibility to assign an JavaScript action on state change
  • Switching between <rich:inplaceSelect> components using "Tab" key
  • Resizable select field
  • Full skinability

Table 6.227. rich : inplaceSelect attributes

Attribute NameDescription
bindingThe attribute takes a value-binding expression for a component property of a backing bean
cancelControlIcon 
changedClass 
controlClass 
controlHover 
controlPressed 
controlsHorizontalPosition 
controlsVerticalPosition 
converterId of Converter to be used or reference to a Converter
converterMessageconverterMessage
defaultLabel 
editClass 
editEvent 
editOnTab 
idEvery component may have a unique id that is automatically created if omitted
immediateA flag indicating that this component value must be converted and validated immediately (that is, during Apply Request Values phase), rather than waiting until a Process Validations phase
layoutinline/block
listHeight 
listWidth 
localValueSetlocalValueSet
maxSelectWidth 
minSelectWidth 
onclickHTML: a script expression; a pointer button is clicked
ondblclickHTML: a script expression; a pointer button is double-clicked
oneditactivated 
oneditactivation 
onkeydownHTML: a script expression; a key is pressed down
onkeypressHTML: a script expression; a key is pressed and released
onkeyupHTML: a script expression; a key is released
onmousedownHTML: script expression; a pointer button is pressed down
onmousemoveHTML: a script expression; a pointer is moved within
onmouseoutHTML: a script expression; a pointer is moved away
onmouseoverHTML: a script expression; a pointer is moved onto
onmouseupHTML: script expression; a pointer button is released
onviewactivated 
onviewactivation 
openOnEdit 
renderedIf "false", this component is not rendered
requiredIf "true", this component is checked for non-empty input
requiredMessagerequiredMessage
saveControlIcon 
selectOnEdit 
selectWidth 
showControls 
tabindex 
validvalid
validatorMethodBinding pointing at a method that is called during Process Validations phase of the request processing lifecycle, to validate the current value of this component
validatorMessagevalidatorMessage
valueThe initial value to set when rendered for the first time
valueChangeListenerListener for value changes
viewClass 
viewHover 

Table 6.228. Component identification parameters

NameValue
component-typeorg.richfaces.inplaceInput
component-familyorg.richfaces.inplaceInput
renderer-typeorg.richfaces.renderkit.inplaceInputRenderer
tag-classorg.richfaces.taglib.inplaceInputTag

6.54.3. Creating the Component with a Page Tag

Here is a simple example of how the component can be used on a page:

Example:


...
<rich:inplaceSelect value="#{Bean.inputValue}" defaultLabel="Click  to edit">
    <f:selectItem itemValue="0" itemLabel="oil well"/>
    <f:selectItem itemValue="1" itemLabel="factory"/>
    <f:selectItem itemValue="2" itemLabel="newspaper"/>
</rich:inplaceSelect>
...

6.54.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.inplaceSelect;
... 
HtmlInpaceSelect myInplaceSelect = new InplaceSelect();
...

6.54.5. Details of Usage

The <rich:inplaceSelect> component has three functional states, which are:

  • View state displays the current value as text;

  • Edit state displays a list with options;

  • Changed state displays the value of the selected option as text

The "value" attribute displays the value as an outputtext. The attribute is defined when some option in the list is selected.

You can form he list of the options: using <f:selectItem> and <f:selectItems>

Please see the example below

Example:


...
<rich:inplaceSelect value="#{inplaceComponentsBean.inputValue}" showControls="true" defaultLabel="click to edit">
    <f:selectItem itemValue="0" itemLabel="oil well"/>
    <f:selectItem itemValue="1" itemLabel="factory"/>
    <f:selectItem itemValue="2" itemLabel="newspaper"/>
</rich:inplaceSelect>
... 

The "value" attribute gets some value when an option in the select-box in clicked on (the default action).

Nowever, if you want the end user to confirm the data saving explicitly you can:

  • Use a "showControls" attribute, which makes "save" and "cancel" buttons (displayed as icons) appear next to the input field;

    Please see the example

    Example:

    
    ...
        <rich:inplaceSelect value="#{inplaceComponentsBean.inputValue}"
            defaultLabel="Click here to edit">
        <f:selectItem itemValue="0" itemLabel="oil well"/>
        <f:selectItem itemValue="1" itemLabel="factory"/>
        <f:selectItem itemValue="2" itemLabel="newspaper"/>
        </rich:inplaceSelect>
    ... 
  • Use standard buttons by means of the controls facet

    Please see the example

    Example:

    
    ...
    <rich:inplaceSelect value="#{inplaceComponentsBean.inputValue}" defaultLabel="Click to edit" showControls="true">
        <f:facet name="controls">
            <input type="button" value="Save"/>
            <input type="button" value="Cancel"/>
        </f:facet>
        <f:selectItem itemValue="0" itemLabel="oil well"/>
        <f:selectItem itemValue="1" itemLabel="factory"/>
        <f:selectItem itemValue="2" itemLabel="newspaper"/>
    </rich:inplaceSelect>
    ... 

Note:

The controls facet also implies using showcontrols attribute and it has to be defined as "true".

Redefinition of the "save" and "cancel" icons can be performed using "saveControlIcon" and "cancelControlIcon" attributes r. You need to define the path to where your images are located.

Example:


...
<rich:inplaceSelect 
   value="#{inplaceComponentsBean.inputValue}" defaultLabel="Click to edit" showControls="true"
    showControls="true"
    controlsHorizontalPosition="left"
    controlsVerticalPosition="top"
    saveControlIcon="/richfaces-demo/richfaces/cancel.gif"
    cancelControlIcon="/richfaces-demo/richfaces/save.gif"> 
    
<f:selectItem itemValue="0" itemLabel="oil well"/>
<f:selectItem itemValue="1" itemLabel="factory"/>
<f:selectItem itemValue="2" itemLabel="newspaper"/>
</rich:inplaceSelect>
    ... 

You can also position the controls relatively to the input field, by means of " controlsHorizontalPosition" " controlsVerticalPosition " attributes. The " controlsHorizontalPosition" attribute has "left", "right" and "center" definitions. The " controlsVerticalPosition " attribute has "bottom", "center" and "top" definitions.

Example:


...
<rich:inplaceSelect value="#{inplaceComponentsBean.inputValue}" defaultLabel="Click to edit"  controlsHorizontalPosition="left" controlsVerticalPosition="top" showControls="true">
    <f:facet name="controls" >
        <input type="button" value="Save"/>
        <input type="button" value="Cancel"/>
    </f:facet>
    <f:selectItem itemValue="0" itemLabel="oil well"/>
    <f:selectItem itemValue="1" itemLabel="factory"/>
    <f:selectItem itemValue="2" itemLabel="newspaper"/>
</rich:inplaceSelect>
... 

Another useful attribute is "openOnEdit" . It allows you to make the drop-down box with options appear once "edit" state activated.

The "editEvent" attribute provides an option to assign an JavaScript action that initiates the change of the state from view to edit. The default value is "click".

Note:

Do not use "on" prefix applying event action. E.g. use "click" instead of "onClick", use "mouseover" instead of "onMouseOver".

The "selectOnEdit" (with possible values "true", "false") gives you an option to make the text in the input area selected right after the change from view state to edit occurs.

The " inputWidth" , " minInputWidth" , and " maxInputWidth" attributes are provided to specify the width, minimal width and maximal width for the input element respectively.

The " oneditactivation" , "oneditactivated" , "onviewactivation" and " onviewactivated" attributes provide a possibility to assign JavaScript code on edit state activation, on edit state activated,on view state activation and on view state activated respectively.

6.54.6. JavaScript API

Table 6.229. JavaScript API

FunctionDescription
edit()changes the state to edit
cancel()changes its state to the previous one before editing (changed or view)
save()the component hanges the state to the previous one before editing (changed or view)
save()the component changes its state to changed with a new value
save()the component changes its state to changed with a new value
getValue()gets the current value
setValue(newValue)sets the current value

6.54.7. Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.

There are two ways to redefine the appearance of all <rich:inplaceSelect> components at once:

  • Redefine the corresponding skin parameters
  • Add to your style sheets style classes used by a <rich:inplaceSelect> component

6.54.8. Relevant Resources Links

Here you can see the example of <rich:inplaceIput> usage and sources for the given example.