JBoss.org Community Documentation

- Prev
- Next

## 6.59. < rich:inplaceSelect >

### 6.59.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

Figure 6.148. Three states of <rich:inplaceSelect> component

### 6.59.2. Key Features

- View/changed/edit states highly customizable representations

- Optional "inline" or "block" element rendering on a page

- Changing state event customization

- Possibility to call custom JavaScript function on state changes

- Edit mode activation when the component got focus with the "Tab"

- Sizes synchronizations between modes

- Highly customizable look and feel

Table 6.250. rich : inplaceSelect attributes

Attribute Name | Description
--- | ---
binding | The attribute takes a value-binding expression for a component property of a backing bean
cancelControlIcon | Defines custom cancel icon
changedClass | CSS style class for changed state
controlClass | CSS style class for controls
controlHover | CSS style class for hovered control
controlPressed | CSS style class for controls pressed
controlsHorizontalPosition | The attribute positions the controls horizontally. Possible values are "right","center","left". Default value is "right".
controlsVerticalPosition | The attribute positions the controls vertically. Possible values are "bottom","top"
converter | Id of Converter to be used or reference to a Converter
converterMessage | A ValueExpression enabled attribute that, if present, will be used as the text of the converter message, replacing any message that comes from the converter
defaultLabel | The attribute is used to display text while value is undefined
editClass | CSS style class for edit state
editEvent | The attribute provides an option to assign an JavaScript action that initiates the change of the state. Default value is "onclick".
id | Every component may have a unique id that is automatically created if omitted
immediate | A 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
layout | Defines how the component is displayed in the layout. Possible values are "block", "inline". Default value is "inline".
listHeight | The attribute defines the height of option list. Default value is "200px".
listWidth | The attribute defines the width of option list. Default value is "200px".
maxSelectWidth | Sets the maximum width of the select element. Default value is "200px".
minSelectWidth | Sets the minimum width of the select element. Default value is "100px".
onblur | HTML: script expression; the element lost the focus
onchange | HTML: script expression; the element value was changed
onclick | HTML: a script expression; a pointer button is clicked
ondblclick | HTML: a script expression; a pointer button is double-clicked
oneditactivated | The attributes provide a possibility to assign JavaScript to be executed when edit state is activated
oneditactivation | The attributes provide a possibility to assign JavaScript on edit state activation
onfocus | HTML: script expression; the element got the focus
oninputblur | HTML: script expression; the element lost the focus
oninputclick | HTML: a script expression; a pointer button is clicked
oninputdblclick | HTML: a script expression; a pointer button is double-clicked
oninputfocus | HTML: script expression; the element got the focus
oninputkeydown | HTML: a script expression; a key is pressed down
oninputkeypress | HTML: a script expression; a key is pressed and released
oninputkeyup | HTML: a script expression; a key is released
oninputmousedown | HTML: script expression; a pointer button is pressed down
oninputmousemove | HTML: a script expression; a pointer is moved within
oninputmouseout | HTML: a script expression; a pointer is moved away
oninputmouseover | HTML: a script expression; a pointer is moved onto
oninputmouseup | HTML: script expression; a pointer button is released
onkeydown | HTML: a script expression; a key is pressed down
onkeypress | HTML: a script expression; a key is pressed and released
onkeyup | HTML: a script expression; a key is released
onmousedown | HTML: script expression; a pointer button is pressed down
onmousemove | HTML: a script expression; a pointer is moved within
onmouseout | HTML: a script expression; a pointer is moved away
onmouseover | HTML: a script expression; a pointer is moved onto
onmouseup | HTML: script expression; a pointer button is released
onselect | HTML: script expression; the onselect event occurs when you select some menu item
onviewactivated | The attributes provide a possibility to assign JavaScript to be executed when view state is activated
onviewactivation | The attributes provide a possibility to assign JavaScript on view state activation
openOnEdit | The attribute opens the list once edit activated. Default value is "true".
rendered | If "false", this component is not rendered
required | If "true", this component is checked for non-empty input
requiredMessage | A ValueExpression enabled attribute that, if present, will be used as the text of the validation message for the "required" facility, if the "required" facility is used
saveControlIcon | Defines custom save icon
selectWidth | Sets width of the select element
showControls | The attribute serves to display "save" and "cancel" controls. Default value is "false".
tabindex | The attribute serves to define the tabbing order
validator | MethodBinding pointing at a method that is called during Process Validations phase of the request processing lifecycle, to validate the current value of this component
validatorMessage | A ValueExpression enabled attribute that, if present, will be used as the text of the validator message, replacing any message that comes from the validator
value | The current value of this component
valueChangeListener | Listener for value changes
viewClass | Style class for view state
viewHover | CSS style class for hovered text in view state

Table 6.251. Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.InplaceSelect
component-class | org.richfaces.component.html.HtmlInplaceSelect
component-family | org.richfaces.InplaceSelect
renderer-type | org.richfaces.renderkit.InplaceSelectRenderer
tag-class | org.richfaces.taglib.InplaceSelectTag

### 6.59.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}">

        <f:selectItem itemValue="1" itemLabel="factory"/>

    </rich:inplaceSelect>

    ...

### 6.59.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.inplaceSelect;

    ...

    HtmlInpaceSelect myInplaceSelect = new InplaceSelect();

    ...

### 6.59.5. Details of Usage

The "value" attribute is a value-binding expression for the current value of the component.

The <rich:inplaceSelect> component has three functional states:

- View state displays default label with the value taken from "value" or "defaultLabel" attributes.

  If the initial value of the "value" attribute is "null" or empty string the "defaultLabel" attribute is used to define default label.

  Example:

      ...

      <rich:inplaceSelect value="#{bean.value}" defaultLabel="click to edit">

          <f:selectItems value="#{bean.selectItems}" />

      </rich:inplaceSelect>

      ...

  In the example above the "value" attribute is not initialized therefore "`click to edit`" text, that "defaultLabel" , contains is displayed.

  This is the result:

  Figure 6.149. View state

- Edit state - select representation to allow value edit

  Figure 6.150. Edit state

- Changed state - value representation after it was changed

  Figure 6.151. Changed state

You can form the list of the options using <f:selectItem/> and <f:selectItems/> facets.

Please, see the example below.

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" defaultLabel="click to edit">

        <f:selectItems  value="#{bean.selectItems}"/>

        <f:selectItem itemValue="1" itemLabel="factory"/>

        <f:selectItem itemValue="2" itemLabel="newspaper"/>

    </rich:inplaceSelect>

    ...

In the example above the value of the selected item is available via "value" attribute.

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 "onclick".

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" defaultLabel="Double Click to edit" editEvent="ondblclick">

        <f:selectItems value="#{demo.selectItems}" />

    </rich:inplaceSelect>

    ...

The <rich:inplaceSelect> component provides specific event attributes:

- "oneditactivation" fired on edit state activation

- "oneditactivated" fired when edit state is activated

- "onviewactivation" fired on view state activation

- "onviewactivated" fired after the component is changed to representation state

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" oneditactivation="if (!confirm('Are you sure you want to change the value?')){return false;}">

        <f:selectItems value="#{demo.selectItems}" />

    </rich:inplaceSelect>

    ...

The given code illustrates how "oneditactivation" attribute works, namely when the state is being changed from view to edit, a confirmation window with a message `"Are you sure you want to change value?"` comes up.

To prevent opening the drop-down list by default, once edit state is activated, set the "openOnEdit" attribute to "false". The default value is "true".

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" showControls="true" openOnEdit="false">

        <f:selectItems  value="#{bean.selectItems}"/>

    </rich:inplaceSelect>

    ...

This is the result:

Figure 6.152. The "openOnEdit" attribute usage

Nowever, if you want to confirm the data saving explicitly you can use the "showControls" attribute, which makes "Save" and "Cancel" buttons (displayed as icons) appear next to the input field. Edit state can be deactivated by pressing "Esc" key. An option in the drop-drown list can be also selected by pressing "Enter".

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" showControls="true">

        <f:selectItems  value="#{bean.selectItems}"/>

    </rich:inplaceSelect>

    ...

This is the result:

Figure 6.153. The "showControls" attribute usage

You can also position the controls relatively to the input field, by means of

- The "controlsHorizontalPosition" attribute with "left", "right" and "center" definitions

- The "controlsVerticalPosition " attribute with "bottom" and "top" definitions

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" controlsHorizontalPosition="left" controlsVerticalPosition="center" showControls="true">

        <f:selectItems  value="#{bean.selectItems}"/>

    </rich:inplaceSelect>

    ...

This is the result:

Figure 6.154. Controls positioning

It is also possible to use "controls" facet in order to replace the default controls with facets content. See the example below.

Please, see the example.

Example:

    ...

    <rich:inplaceSelect value="#{bean.inputValue}" showControls="true">

        <f:facet name="controls">

            <button onclick="#{rich:component('inplaceSelect')}.save();" type="button">Save</button>

            <button onclick="#{rich:component('inplaceSelect')}.cancel();" type="button">Cancel</button>

        </f:facet>

        <f:selectItems  value="#{bean.selectItems}"/>

    </rich:inplaceSelect>

    ...

This is the result:

Figure 6.155. "controls" facet usage

## Note:

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

The <rich:inplaceSelect> component could be rendered with <span> or <div> elements to display its value. In order to change default <span> output, use the "layout" attribute with "block" value.

The <rich:inplaceSelect> component supports standard "tabindex" attribute. When the component gets focus the edit mode is activated and drop-down list is opened.

The "selectWidth" , "minSelectWidth" and "maxSelectWidth" attributes are provided to specify the width, minimal width and maximal width for the input element respectively.

In order to specify the height and width parameters for the list items of the component, you can use "listHeight" and " listWidth" attributes.

### 6.59.6. JavaScript API

Table 6.252. JavaScript API

Function | Description
--- | ---
edit() | Changes the state to edit
cancel() | Changes its state to the previous one before editing (changed or view)
save() | Changes its state to changed with a new value
getValue() | Gets the current value
setValue(newValue) | Sets the current value (to be implemented)

### 6.59.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.59.8. Skin Parameters Redefinition

Table 6.253. Skin parameters redefinition for view state

Skin parameters | CSS properties
--- | ---
editorBackgroundColor | background-color
generaTextColor | border-bottom-color

Table 6.254. Skin parameters redefinition for input field in edit state

Skin parameters | CSS properties
--- | ---
editBackgroundColor | background-color
panelBorderColor | border-color

Table 6.255. Skin parameters redefinition for control

Skin parameters | CSS properties
--- | ---
tabBackgroundColor | background-color
panelBorderColor | border-color

Table 6.256. Skin parameters redefinition for pressed control

Skin parameters | CSS properties
--- | ---
tabBackgroundColor | background-color
panelBorderColor | border-color

Table 6.257. Skin parameters redefinition for list

Skin parameters | CSS properties
--- | ---
editBackgroundColor | background-color
panelBorderColor | border-color

Table 6.258. Skin parameters redefinition for selected item

Skin parameters | CSS properties
--- | ---
headerTextColor | color
headerBackgroundColor | background-color
headerBackgroundColor | border-color

### 6.59.9. Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Figure 6.156. Classes names

Table 6.259. Class name for the view state

Class name | Description
--- | ---
rich-inplace-select-view | Defines styles for the select view

Table 6.260. Class name for the input field in edit state

Class name | Description
--- | ---
rich-inplace-select-field | Defines styles for the select field

Table 6.261. Class name for the control

Class name | Description
--- | ---
rich-inplace-select-control | Defines styles for the select control
rich-inplace-select-control-press | Defines styles for the pressed select control

Table 6.262. Class name for the list

Class name | Description
--- | ---
rich-inplace-select-list-decoration | Defines styles for a wrapper <table> element of an inplaceSelect

Table 6.263. Classes names for the selected item

Class name | Description
--- | ---
rich-inplace-select-selected-item | Defines styles for the selected item

Table 6.264. Classes names for the shadow

Class name | Description
--- | ---
rich-inplace-select-shadow-tl | Defines styles for the top-left shadow
rich-inplace-select-shadow-tr | Defines styles for the top-right shadow
rich-inplace-select-shadow-bl | Defines styles for the bottom-left shadow
rich-inplace-select-shadow-br | Defines styles for the bottom-right shadow

In order to redefine styles for all <rich:inplaceSelect> components on a page using CSS, it's enough to create classes with the same names (possible classes could be found in the tables above) and define necessary properties in them.

Example:

    ...

    .rich-inplace-select-list-decoration{

        background-color: #ecf4fe;

    }

    ...

This is the result:

Figure 6.157. Redefinition styles with predefined classes

In the shown example the background color for list is changed.

It's aslo possible to change styles of a particular <rich:inplaceSelect> component. In this case you should create own style classes and use them in corresponding <rich:inplaceSelect> styleClass attributes. An example is placed below:

Example:

    ...

    .myClass {

        background-color:#bed6f8;

        font-style:italic;}

    ...

The "viewClass" attribute for <rich:inplaceSelect> is defined as it's shown in the example below:

Example:

    <rich:inplaceSelect value="click to edit" viewClass="myClass"/>

This is a result:

Figure 6.158. Modificaton of a look and feel with own classes and styleClass attributes

As it could be seen on the picture above, the font style and background color in view state is changed.

### 6.59.10. Relevant Resources Links

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

- Prev6.58. < rich:inplaceInput >
- Top of page
- Front page
- Next6.60. < rich:inputNumberSlider >