6.53.  < rich:inplaceInput >

6.53.1. Description

The <rich:inplaceInput> is an input component used for displaying and editing data inputted.

<rich:inplaceInput> component

Figure 6.106.  <rich:inplaceInput> component


6.53.2. Key Features

  • View/changed/edit states highly customizable representations

  • Changing state event customization

  • Possibility to call custom JavaScript function on state changes

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

  • Edit mode activation when the component gets focus with the "Tab"

  • Sizes synchronizations between modes

  • Controls customization

Table 6.216. rich : inplaceInput attributes

Attribute NameDescription
bindingThe attribute takes a value-binding expression for a component property of a backing bean
cancelControlIconDefines custom cancel icon
changedClassCSS style class for changed state
changedHoverClassCSS style class for hovered text in changed state
controlClassCSS style class for controls
controlHoverClassCSS style class for hovered control
controlPressedClassCSS style class for pressed press controls
controlsHorizontalPositionPositions the controls horizontally. Possible values are "left", "center", "right". Default value is "right".
controlsVerticalPositionPositions the controls vertically. Possible values are "bottom", "center", "top". Default value is "center".
converterId of Converter to be used or reference to a Converter
converterMessageA ValueExpression enabled attribute that, if present, will be used as the text of the converter message, replacing any message that comes from the converter
defaultLabelThe attribute is used to display text while value is undefined
editClassCSS style class for edit state
editEventProvides an option to assign an JavaScript action that initiates the change of the state. Default value is "onclick".
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
inputWidthSets width of the input field
layoutDefines how the component is displayed in the layout. Possible values are "block", "inline". . Default value is "inline".
maxInputWidthSets the maximum width of the input field. Default value is "500px".
minInputWidthSets the minimum width of the input field. Default value is "40px".
onblurHTML: script expression; the element lost the focus
onchangeHTML: script expression; the element value was changed
onclickHTML: a script expression; a pointer button is clicked
ondblclickHTML: a script expression; a pointer button is double-clicked
oneditactivatedProvides a possibility to assign JavaScript to be executed when edit state is activated
oneditactivationProvides a possibility to assign JavaScript on edit state activation
onfocusHTML: script expression; the element got the focus
oninputclickHTML: a script expression; a pointer button is clicked
oninputdblclickHTML: a script expression; a pointer button is double-clicked
oninputkeydownHTML: a script expression; a key is pressed down
oninputkeypressHTML: a script expression; a key is pressed and released
oninputkeyupHTML: a script expression; a key is released
oninputmousedownHTML: script expression; a pointer button is pressed down
oninputmousemoveHTML: a script expression; a pointer is moved within
oninputmouseoutHTML: a script expression; a pointer is moved away
oninputmouseoverHTML: a script expression; a pointer is moved onto
oninputmouseupHTML: script expression; a pointer button is released
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
onselectHTML: script expression; the onselect event occurs when you select some menu item
onviewactivatedProvides a possibility to assign JavaScript to be executed when view state is activated
onviewactivationProvides a possibility to assign JavaScript on view state activation
renderedIf "false", this component is not rendered
requiredIf "true", this component is checked for non-empty input
requiredMessageA 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
saveControlIconDefines custom save icon
selectOnEditMakes the input field select when switched to edit state. Default value is "false"
showControlsServes to display "save" and "cancel" controls. Default value is "false".
styleClassCorresponds to the HTML class attribute
tabindexServes to define the tabbing order
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
validatorMessageA ValueExpression enabled attribute that, if present, will be used as the text of the validator message, replacing any message that comes from the validator
valueThe current value of this component
valueChangeListenerListener for value changes
viewClassCSS style class for view state
viewHoverClassCSS style class for hovered text in view state

Table 6.217. Component identification parameters

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

6.53.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:inplaceInput value="#{bean.value}"/>
...

6.53.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.inplaceInput;
... 
HtmlInpaceInput myInplaceInput = new InplaceInput();
...

6.53.5. Details of Usage

The <rich:inplaceInput> component was designed to facilitate displaying and inputting(editing) some data.

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

The 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:inplaceInput value="#{bean.value}" defaultLabel="click to edit"/>
    ... 

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

    This is the result:

    View state

    Figure 6.107. View state


  • Edit state - input representation to allow value edit

    Edit state

    Figure 6.108. Edit state


  • Changed state - value representation after it was changed

    Changed state

    Figure 6.109. Changed state


The "editEvent" attribute provides an option to assign a JavaScript action to initiate the change of the state from view/changed to edit. The default value is "onclick".

Example:


...
<rich:inplaceInput value="#{bean.value}" editEvent="ondblclick"/> 
... 

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

  • "oneditactivation" which is fired on edit state activation

  • "oneditactivated" which is fired when edit state is activated

  • "onviewactivation" which is fired on view state activation

  • "onviewactivated" which is fired after the component is changed to representation state

Example:


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

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.

Using the boolean "selectOnEdit" attribute set to true, the text in the input field will be selected when the change from view/changed state to edit occurs.

This is the result:

Usage of the "selectOnEdit" attribute

Figure 6.110. Usage of the "selectOnEdit" attribute


If the <rich:inplaceInput> loses focus, input data is saved automatically and the component displays a new value. Additionally, the data is saved when "Enter" is pressed. Nevertheless, you can use the "showControls" attribute, which makes "Save" and "Cancel" buttons appear next to the input field. If the controls are used, data is not saved automatically when the form loses focus: user has to confirm that he/she wants to save/discard the data explicitly. In both cases(with controls or without them) the input data can be discarded by pressing "Esc" key.

Example:


...
<rich:inplaceInput value="#{bean.value}" showControls="true"/>
... 
Usage "showControls" attribute

Figure 6.111. Usage "showControls" attribute


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", "center" and "top" definitions

Example:


...
<rich:inplaceInput value="#{bean.value}" showControls="true" controlsVerticalPosition="bottom" controlsHorizontalPosition="left"/>
... 

This is the result:

Positioning of "Save" and "Cancel" buttons

Figure 6.112. Positioning of "Save" and "Cancel" buttons


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

Example:


...
<rich:inplaceInput defaultLabel="Click here to edit" showControls="true" controlsHorizontalPosition="left" controlsVerticalPosition="bottom" id="inplaceInput">
    <f:facet name="controls">
        <button onclick="#{rich:component('inplaceInput')}.save();" type="button">Save</button>
        <button onclick="#{rich:component('inplaceInput')}.cancel();" type="button">Cancel</button>
    </f:facet>
</rich:inplaceInput>
... 

This is the result:

"controls" facet usage

Figure 6.113.  "controls" facet usage


Note:

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

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

The <rich:inplaceInput> component supports standard "tabindex" attribute. When the component gets focus the edit mode is activated.

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

Table 6.218. Keyboard usage

Keys and combinations Description
ENTERSaves the input data, and changes the state from edit to changed
ESCChanges the state from edit to view or changed, value is not affected
TABSwitches between the components

6.53.6. JavaScript API

Table 6.219. JavaScript API

FunctionDescription
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

6.53.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:inplaceInput> components at once:

  • Redefine the corresponding skin parameters

  • Add to your style sheets style classes used by a <rich:inplaceInput> component

6.53.8. Skin Parameters Redefinition

Table 6.220. Skin parameters redefinition for "save" and "cancel" controls

Skin parametersCSS properties
tabBackgroundColorbackground-color
panelBorderColorborder-color
panelBorderColorborder-color

Table 6.221. Skin parameters redefinition for view state

Skin parametersCSS properties
editorBackgroundColorbackground-color
generalTextColorborder-bottom-color

Table 6.222. Skin parameters redefinition for "Changed" state

Skin parametersCSS properties
editorBackgroundColorbackground-color
generalTextColoborder-bottom-color

Table 6.223. Classes names that define input field look and feel in edit state

Skin parametersCSS properties
editBackgroundColorbackground-color
panelBorderColorborder-color

6.53.9. Definition of Custom Style Classes

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

Classes names

Figure 6.114. Classes names


Table 6.224. Class name for the view state

Class nameDescription
rich-inplace-viewDefines styles for the view state
rich-inplace-input-view-hoverDefines styles for hovered text in the view state

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

Class nameDescription
rich-inplace-fieldDefines styles for input field look and feel in edit state

Table 6.226. Class name for the "Changed" state

Class nameDescription
rich-inplace-changedDefines styles for the "Changed" state
rich-inplace-input-changed-hover Defines styles for the hovered text in the "Changed" state

Table 6.227. Classes names "save" and "cancel" controls in Edit state

Class nameDescription
rich-inplace-controlDefines styles for the controls
rich-inplace-control-pressDefines styles for the controls when either of the buttons is pressed
rich-inplace-shadow-sizeDefines size of the shadow
rich-inplace-shadow-tlDefines styles for the shadow in the top left corner
rich-inplace-shadow-trDefines styles for the shadow in the top right corner
rich-inplace-shadow-blDefines styles for the shadow in the bottom left corner
rich-inplace-shadow-brDefines 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: italic;
}                     
   
...

This is the result:

Redefinition styles with predefined classes

Figure 6.115. Redefinition styles with predefined classes


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 "viewClass" attribute for the <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:

Modificaton of a look and feel with own classes and styleClass attributes

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


As it could be seen on the picture above, the font color of the text on the component was changed.

6.53.10. Relevant Resources Links

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