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
Table 6.228. 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 postions the controls horizontally |
controlsVerticalPosition | The attribute postions the controls vertically |
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 |
editOnTab | The attribute activates edit state once Tab key pressed |
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, can be block or inline |
listHeight | The attribute defines the height of option list |
listWidth | The attribute defines the withs of option list |
maxSelectWidth | max width of the select element |
minSelectWidth | min width of the select element |
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 code to be executed when edit state is activated |
oneditactivation | The attributes provide a possibility to assign JavaScript code on edit state activation |
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 |
onviewactivated | The attributes provide a possibility to assign JavaScript code to be executed when view state is activated |
onviewactivation | The attributes provide a possibility to assign JavaScript code on view state activation |
openOnEdit | The attribure opens the list once edit activated |
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 |
selectOnEdit | The attribute make the input field select when switched to edit state |
selectWidth | width of the select element |
showControls | The attribute serves to display "save" and "cancel" controls |
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 initial value to set when rendered for the first time |
valueChangeListener | Listener for value changes |
viewClass | Style class for view state |
viewHover | CSS style class for hovered text in view state |
Table 6.229. Component identification parameters
Name | Value |
---|---|
component-type | org.richfaces.inplaceInput |
component-family | org.richfaces.inplaceInput |
renderer-type | org.richfaces.renderkit.inplaceInputRenderer |
tag-class | org.richfaces.taglib.inplaceInputTag |
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:selectItems value="#{bean.selectItems}"/>
<f:selectItem itemValue="1" itemLabel="factory"/>
<f:selectItem itemValue="2" itemLabel="newspaper"/>
</rich:inplaceSelect>
...
Example:
import org.richfaces.component.html.inplaceSelect;
...
HtmlInpaceSelect myInplaceSelect = new InplaceSelect();
...
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:selectItems value="#{bean.selectItems}"/>
<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>
...
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".
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.
In order to specify the height and width parameters for the list items of the component, you can use "listHeight" and " listWidth" attributes.
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.
Table 6.230. JavaScript API
Function | Description |
---|---|
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 |
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:
Table 6.231. Skin parameters redefinition for view state
Skin parameters | CSS properties |
---|---|
editorBackgroundColor | background-color |
generaTextColor | border-bottom-color |
Table 6.232. Skin parameters redefinition for input field in edit state
Skin parameters | CSS properties |
---|---|
editBackgroundColor | background-color |
panelBorderColor | border-color |
Table 6.233. Skin parameters redefinition for control
Skin parameters | CSS properties |
---|---|
tabBackgroundColor | background-color |
panelBorderColor | border-color |
Table 6.234. Skin parameters redefinition for pressed control
Skin parameters | CSS properties |
---|---|
tabBackgroundColor | background-color |
panelBorderColor | border-color |
Table 6.235. Skin parameters redefinition for list
Skin parameters | CSS properties |
---|---|
editBackgroundColor | background-color |
panelBorderColor | border-color |
Table 6.236. Skin parameters redefinition for selected item
Skin parameters | CSS properties |
---|---|
headerTextColor | color |
headerBackgroundColor | background-color |
headerBackgroundColor | border-color |
On the screenshot there are classes names that define styles for component elements.
Table 6.237. Class name for the view state
Class name | Description |
---|---|
rich-inplace-select-view | Defines styles for the select view |
Table 6.238. Class name for the input field in edit state
Class name | Description |
---|---|
rich-inplace-select-field | Defines styles for the select field |
Table 6.239. 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.240. 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.241. Classes names for the selected item
Class name | Description |
---|---|
rich-inplace-select-selected-item | Defines styles for the selected item |
Table 6.242. 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:
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:
As it could be seen on the picture above, the font style and background color in view state is changed.
Here you can see the example of <rich:inplaceIput> usage and sources for the given example.