JBoss.orgCommunity Documentation
The <rich:inplaceInput> is an input component used for displaying and editing data inputted.
View/changed/edit states in 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
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 the default label with the value taken from the "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 the "click to edit
" text, that
"defaultLabel"
contains, is displayed.
This is the result:
Edit state - input representation to allow value edit
Changed state - value representation after it was changed
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 the 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:
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"/>
...
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:
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">
<h:commandButton value="Save" onclick="#{rich:component('inplaceInput')}.save();" type="button" />
<h:commandButton value="Cancel" onclick="#{rich:component('inplaceInput')}.cancel();" type="button" />
</f:facet>
</rich:inplaceInput>
...
This is the result:
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. 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="/images/cancel.gif"
cancelControlIcon="/images/save.gif"/>
...
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 the 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.185. 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 of <rich:inplaceInput> attributes.
Table 6.186. Component Identification Parameters
Name | Value |
---|---|
component-type | org.richfaces.inplaceInput |
component-class | org.richfaces.component.html.HtmlInplaceInput |
component-family | org.richfaces.inplaceInput |
renderer-type | org.richfaces.renderkit.inplaceInputRenderer |
tag-class | org.richfaces.taglib.inplaceInputTag |
Table 6.187. 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) |
Table 6.188. Facets
Facet name | Description |
---|---|
controls | Defines the contols contents. Related attributes are "saveControlIcon" and "cancelControlIcon" |
Table 6.189. Style classes (selectors) with the corresponding skin parameters
Class (selector) name | Description | Skin Parameters | CSS properties mapped |
---|---|---|---|
.rich-inplace-control | Defines styles for the controls | tabBackgroundColor | background-color |
panelBorderColor | border-color | ||
.rich-inplace-control-press | Defines styles for the controls when either of the buttons is pressed | tabBackgroundColor | background-color |
panelBorderColor | border-color | ||
.rich-inplace-view | Defines styles for the view state | editorBackgroundColor | background-color |
generalTextColor | border-bottom-color | ||
.rich-inplace-changed | Defines styles for the "Changed" state | editorBackgroundColor | background-color |
generalTextColor | border-bottom-color | ||
input.rich-inplace-field | Defines styles for the input field in edit state | editorBackgroundColor | background-color |
panelBorderColor | border-color |
Table 6.190. Style classes (selectors) without skin parameters
Class name | Description |
---|---|
.rich-inplace | Defines styles for a wrapper <span> (or <div>) element of a component |
.rich-inplace-input | Defines styles for the component input field |
.rich-inplace-input-view-hover | Defines styles for hovered text in the view state |
.rich-inplace-field | Defines styles for the input field look and feel in edit state |
.rich-inplace-input-changed-hover | Defines styles for the hovered text in the "Changed" state |
.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 |
You can find all necessary information about style classes redefinition in Definition of Custom Style Classes section.
On the component Live Demo page you can see the example of <rich:inplaceIput> usage and sources for the given example.