The <rich:inplaceInput> is an input component used for displaying and editing textual data
Table 6.217. rich : inplaceInput attributes
Attribute Name | Description |
---|---|
binding | The attribute takes a value-binding expression for a component property of a backing bean |
cancelControlIcon | |
changedClass | |
changedHoverClass | |
controlClass | |
controlHoverClass | |
controlPressedClass | |
controlsHorizontalPosition | |
controlsVerticalPosition | |
converter | Id of Converter to be used or reference to a Converter |
converterMessage | converterMessage |
defaultLabel | |
editClass | |
editEvent | |
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 |
inputWidth | |
layout | inline/block |
maxInputWidth | |
minInputWidth | |
onblur | |
onchange | |
onclick | HTML: a script expression; a pointer button is clicked |
ondblclick | HTML: a script expression; a pointer button is double-clicked |
oneditactivated | |
oneditactivation | |
onfocus | |
oninputclick | HTML: a script expression; a pointer button is clicked |
oninputdblclick | HTML: a script expression; a pointer button is double-clicked |
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 | |
onviewactivated | |
onviewactivation | |
rendered | If "false", this component is not rendered |
required | If "true", this component is checked for non-empty input |
requiredMessage | requiredMessage |
saveControlIcon | |
selectOnEdit | |
showControls | |
styleClass | |
tabindex | |
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 | validatorMessage |
value | The initial value to set when rendered for the first time |
valueChangeListener | Listener for value changes |
viewClass | |
viewHoverClass |
Table 6.218. 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:inplaceInput value="#{bean.value}"/>
...
Example:
import org.richfaces.component.html.inplaceInput;
...
HtmlInpaceInput myInplaceInput = new InplaceInput();
...
As it was mentioned earlier the <rich:inplaceInput> component was designed to facilitate inputting and editing some parts of text.
The component has three logical states:
View state displays the text containing in a "value" attribute;
;Editstate - the text can be edited and saved;
Changedstate - displays the edited text and indicates that it was edited, changed
The main attribute of the component is "value" it displays the text on a page, the text can be edited by clicking (default action, which can be redefined) on it.
However, if "value" attribute is not defined, you can use "defaultLabel" attribute which displays some default text while "value" attribute stays undefined.
Example:
...
<rich:inplaceInput value="#{bean.value}" defaultLabel="click to edit"/>
...
In the shown example, "value" attribute is not defined; therefore default text "Click to edit" is displayed since it is placed into the "defaultLabel" attribute.
Input data is saved (submitted) automatically whenever the input field loses focus. Nevertheless, you can use the "showControls" attribute, which makes "save"and "cancel" buttons appear next to the input field.
Example:
...
<rich:inplaceInput value="#{bean.value}" defaultLabel='click to edit' showControls="true"/>
...
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.
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:inplaceInput value="#{bean.value}" defaultLabel='click to edit'
showControls="true"
controlsHorizontalPosition="left"
controlsVerticalPosition="top"
saveControlIcon="/richfaces-demo/richfaces/cancel.gif"
cancelControlIcon="/richfaces-demo/richfaces/save.gif"/>
...
The "inputWidth" , "minInputWidth" , and "maxInputWidth" attributes are provided to specify the width, minimal width and maximal width for the input element respectively.
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".
Having multiple <rich:inplaceInput> components on a page you can use "tabindex" attribute that enables switching (tabbing) between the components by pressing the “Tab” key. Switching order is determined by the value of the attribute which is an integer between 0 and 32767.
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 " oneditactivation" , "oneditactivated" , "onviewactivation" and " onviewactivated" 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.
Example:
...
<rich:inplaceInput value="#{bean.value}" defaultLabel='click to edit'
onviewactivated="if (confirm('Are you sure you want to change value?')){return false;}" />
...
The given code illustrates how onviewactivation attribute works, namely when the state is being changed from edit to view, a confirmation window with a message "Are you sure you want to change value?" comes up.
Table 6.219. Keyboard usage
Keys and combinations | Description |
---|---|
ENTER | Saves the input data, and changes the state from edit to changed |
ESC | changes the state from edit to view or changed, value is not affected |
TAB | switches between the components |
Table 6.220. 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:inplaceInput> components at once:
Table 6.221. Skin parameters redefinition for "save" and "cancel" controls
Skin parameters | CSS properties |
---|---|
tabBackgroundColor | background-color |
panelBorderColor | border-color |
panelBorderColor | border-color |
Table 6.222. Skin parameters redefinition for view state
Skin parameters | CSS properties |
---|---|
editorBackgroundColor | background-color |
generalTextColor | border-bottom-color |
Table 6.223. Skin parameters redefinition for "Changed" state
Skin parameters | CSS properties |
---|---|
editorBackgroundColor | background-color |
generalTextColo | border-bottom-color |
Table 6.224. Classes names that define input field look and feel in edit state
Skin parameters | CSS properties |
---|---|
editBackgroundColor | background-color |
panelBorderColor | border-color |
On the screenshot there are classes names that define styles for component elements.
Table 6.225. Class name for the view state
Class name | Description |
---|---|
rich-inplace-view | Defines styles for the view state |
rich-inplace-input-view-hover | Defines styles for hovered text in the view state |
Table 6.226. Class name for the input field in edit state
Class name | Description |
---|---|
rich-inplace-field | Defines styles for input field look and feel in edit state |
Table 6.227. Class name for the "Changed" state
Class name | Description |
---|---|
rich-inplace-changed | Defines styles for the "Changed" state |
rich-inplace-input-changed-hover | Defines styles for the hovered text in the "Changed" state |
Table 6.228. Classes names "save" and "cancel" controls in Edit state
Class name | Description |
---|---|
rich-inplace-control | Defines styles for the controls |
.rich-inplace-control-press | Defines styles for the controls when either of the buttons is pressed |
.rich-inplace-shadow-size | Defines size of the shadow |
rich-inplace-shadow-tl | Defines styles for the shadow in the top left corner |
rich-inplace-shadow-tr | Defines styles for the shadow in the top right corner |
rich-inplace-shadow-bl | Defines styles for the shadow in the bottom left corner |
rich-inplace-shadow-br | Defines styles for the shadow in the bottom right corner |
In order to redefine styles for all <rich:inplaceInput> 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-field {
font-style: bold;
}
...
This is the result:
In the shown example the font in edit state is changed to bold.
It's aslo possible to change styles of a particular <rich:inplaceInput> component. In this case you should create own style classes and use them in corresponding <rich:inplaceInput> styleClass attributes. An example is placed below:
Example:
...
.myClass {
color: #008cca;
}
...
The "styleClass" attribute for <rich:inplaceInput> is defined as it’s shown in the example below:
Example:
...<rich:inplaceInput value="click to edit" styleClass="myClass"/>
This is a result:
As it could be seen on the picture above, the font color of the text on the component was changed.
Here you can see the example of <rich:inplaceIput> usage and sources for the given example.