6.53.  < rich:inplaceInput >

6.53.1. Description

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

<rich:inplaceInput> component

Figure 6.103.  <rich:inplaceInput> component


6.53.2. Key Features

  • Option to display "save", "cancel" buttons
  • Possibility to assign an JS action on state change
  • Switching between <rich:inplaceInput> components using "Tab" key
  • Resizable input field

Table 6.216. rich : inplaceInput attributes

Attribute NameDescription
bindingThe attribute takes a value-binding expression for a component property of a backing bean
cancelControlIcon 
changedClass 
changedHoverClass 
controlClass 
controlHoverClass 
controlPressedClass 
controlsHorizontalPosition 
controlsVerticalPosition 
converterId of Converter to be used or reference to a Converter
converterMessageconverterMessage
defaultLabel 
editClass 
editEvent 
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
inputWidth 
layoutinline/block
maxInputWidth 
minInputWidth 
onblur 
onchange 
onclickHTML: a script expression; a pointer button is clicked
ondblclickHTML: a script expression; a pointer button is double-clicked
oneditactivated 
oneditactivation 
onfocus 
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
onselect 
onviewactivated 
onviewactivation 
renderedIf "false", this component is not rendered
requiredIf "true", this component is checked for non-empty input
requiredMessagerequiredMessage
saveControlIcon 
selectOnEdit 
showControls 
styleClass 
tabindex 
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 
viewHoverClass 

Table 6.217. Component identification parameters

NameValue
component-typeorg.richfaces.inplaceInput
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

As it was mentioned earlier the <rich:inplaceInput> component was designed to facilitate inputting and editing some parts of a text.

The component has three logical states:

  • "View" state displays the text containing in a "value" attribute;

    "View" state

    Figure 6.104. "View" state


  • "Editable"state - the text can be edited and saved;

    "Editable" state

    Figure 6.105. "Editable" state


  • "Changed"state - displays the edited text and indicates that it was edited, changed

    "Changed" state

    Figure 6.106. "Changed" state


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 will display 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 when the input field loses focus. Nevertheless, you can use a "showControls" attribute, which make "save"and "cancel" buttons appear next to the input field.

Example:


...
<rich:inplaceInput value="#{bean.value}" defaultLabel='click to edit' showControls="true"/>
... 
Usage "showControls" attribute

Figure 6.107. Usage "showControls" attribute


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.

Positioning of "save" and "cancel" buttons

Figure 6.108. Positioning of "save" and "cancel" buttons


Redefinition of the "save" and "cancel" icons can be performed using "saveControlIcon" and "cancelControlIcon" attributes relatively. 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"/> 
    ... 
Redefining of "save" and "cancel" buttons

Figure 6.109. Redefining of "save" and "cancel" buttons


The "editEvent" attribute provides an option to assign an JS action that triggers state changing 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".

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

6.53.6. JavaScript API

Table 6.219. JavaScript API

FunctionDescription
enable()Begins polling for ajax mode
disable()Stops polling for ajax mode
setValue(value)Updates the progress of the process
setLabel(label)Update the label for the process

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:progressBar> components at once:

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

6.53.8. Skin Parameters Redefinition

Table 6.220. Skin parameters redefinition for the "completed" part of the bar with no label

Skin parametersCSS properties
selectControlColorbackground-color

Table 6.221. Skin parameters redefinition for the "completed" part of the bar with a label used

Skin parametersCSS properties
panelBorderColorborder-color

Table 6.222. Skin parameters redefinition for the “completed” part of the bar with a label used

Skin parametersCSS properties
selectControlColorbackground-color
controlBackgroundColorcolor

Table 6.223. Skin parameters redefinition for the "remained" part of the bar

Skin parametersCSS properties
controlBackgroundColorbackground-color
controlTextColorcolor

Table 6.224. Skin parameters redefinition for the bar itself with a label used

Skin parametersCSS properties
panelBorderColorborder-color
generalFamilyFontfont-family
headerFamilyFontfont-family
generalSizeFontfont-size
controlTextColorcolor

Table 6.225. Skin parameters redefinition for the bar itself with no label used

Skin parametersCSS properties
controlBackgroundColorbackground-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.110. Classes names


Table 6.226. Classes names for the bar

Class nameDescription
rich-progress-bar-shellDefines styles for the background and the borders of the bar when label is not used
rich-progress-bar-shell-digDefines styles for background, font and border settings when label is used

Table 6.227. Classes names that define "completed" part of the bar

Class nameDescription
rich-progress-bar-uploadedDefines styles for of "completed" progress area with no labels used
rich-progress-bar-uploaded-digDefines styles for that "completed" progress area with labels used
rich-progress-bar-completedDefines styles for the "completed" progress area with a label used

Table 6.228. Classes names that define "remained" part of the progress area

Class nameDescription
rich-progress-bar-remainedDefines styles for the "remained" part of the bar

In order to redefine styles for all <rich:progressBar> 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-progress-bar-remained{                                    
    
background-color: #ebf3fd;                         
}  
...

This is the result:

Redefinition styles with predefined classes

Figure 6.111. Redefinition styles with predefined classes


In the example the "remained" part of progress area is modified with a background-color CSS property.

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

Example:


...
.RremainClass{  background-color: #ebf3fd;}
...

The "styleClass" attribute for <rich:progressBar> is defined as it’s shown in the example below:

Example:


<rich:progressBar value="#{bean.incValue1}" styleClass="remainClass" />

This is a result:

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

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


As it could be seen on the picture above, the font style for output text was changed.

6.53.10. Relevant Resources Links

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