### Create new RichFaces Documentation Jira issue

Summary
255 characters left
Description
Environment
This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.org Community Documentation

- Prev
- Next

### 6.11.4. < rich:editor > available since 3.3.0

expand all

#### 6.11.4.1. Description

The <rich:editor> component is used for creating a WYSIWYG editor on a page.

Figure 6.133. <rich:editor> component

#### 6.11.4.2. Key Features

- Seam text support

- Manageable global configurations

- Possibility to use custom plug-ins

- Support of all TinyMCE's parameters through <f:param>

#### 6.11.4.3. Details of Usage

The <rich:editor> is fully based on TinyMCE web based Javascript HTML WYSIWYG editor control and supports all of the features it has. The <rich:editor> adapts the TinyMCE editor for JSF environment and adds some functional capabilities.

The easiest way to place the <rich:editor> on a page is as follows:

Example:

    <rich:editor value="#{bean.editorValue}" />

Implementation of <rich:editor> provides three ways to define the properties of the component:

1. Using attributes

2. Using using <f:param> JSF tag

3. Using configuration files that allow you to set up multiple configurations for all editors in your application and change them in the runtime

The three methods are described in details in the chapter.

The most important properties are implemented as attributes and you can define them as any other attribute. The attributes of the <rich:editor> component match the corresponding properties of TinyMCE editor.

For example, a theme for the editor can be defined using the "theme" attribute like this:

Example:

    <rich:editor value="#{bean.editorValue}" theme="advanced" />

Setting a different skin for the editor can be done using the "skin" attribute.

Another useful property that is implemented at attribute level is "viewMode" . The attribute switches between "visual" and "source" modes, toggling between modes is performed setting the attribute to "visual" and "source" respectively. Implementation of <rich:editor> also implies that you can change the modes dynamically setting the value of the "viewMode" attribute using EL-expression.

Example:

    ...

    <rich:editor value="#{editor.submit}" theme="advanced" viewMode="#{editor.viewMode}" >

        ...

        <h:selectOneRadio value="#{editor.viewMode}" onchange="submit();">

            <f:selectItem itemValue="visual" itemLabel="visual" />

            <f:selectItem itemValue="source" itemLabel="source" />

        </h:selectOneRadio>

        ...

    </rich:editor>

    ...

Most configuration options that TinyMCE provides can be applied using <f:param> JSF tag. The syntax is quite simple: the "name" attribute should contain the option, the "value" attribute assigns some value to the option.

For example, this code adds some buttons to the editor and positions the toolbar.

Example:

    ...

    <rich:editor value="#{bean.editorValue}" theme="advanced" plugins="save,paste" >

              <f:param name="theme_advanced_buttons1" value="bold,italic,underline, cut,copy,paste,pasteword"/>

              <f:param name="theme_advanced_toolbar_location" value="top"/>

              <f:param name="theme_advanced_toolbar_align" value="left"/>

    </rich:editor>

    ...

This is what you get as a result:

Figure 6.134. Setting configuration options with <f:param>

The third way to configure the <rich:editor> is to use configuration file (.properties)

This method eases your life if you need to configure multiple instances of the <rich:editor> : you configure the editor once and in one spot and the configuration properties can be applied to any <rich:editor> in your application.

To implement this type of configuration you need to take a few steps:

- Create a configuration file (.properties) in the classpath folder and add some properties to it. Use standard syntax for the .properties files: `parameter=value`. Here is an example of configuration file:

  Example:

      theme="advanced"

      plugins="save,paste"

      theme_advanced_buttons1="bold,italic,underline, cut,copy,paste,pasteword"

      theme_advanced_toolbar_location="top"

      theme_advanced_toolbar_align="left"

- The properties stored in configuration file are passed to the <rich:editor> via "configuration" attribute which takes the name of the configuration file as a value (with out .properties extension).

  For example, if you named the configuration file "editorconfig", you would address it as follows:

  Example:

      ...

      <rich:editor value="#{bean.editorValue}" configuration="editorconfig"/>

      ...

- Alternately, you can use a EL-expression to define a configuration file. This way you can dynamically change the sets of configuration properties.

  For example, you have two configuration files "configurationAdvanced" and "configurationSimple" and you want them to be applied under some condition.

  To do this you need to bind "configuration" attribute to the appropriate bean property like this.

  Example:

      ...

      <rich:editor value="#{bean.editorValue}" configuration="#{editor.configuration}" />

      ...

  Your Java file should look like this.

      ...

      String configuration;

      if(some condition){//defines some condition

              configuration = "configurationAdvanced"; //the name on the file with advanced properties

      }

      else{

              configuration= "configurationSimple"; //the name on the file with simplified properties

      }

      ...

You also might want to add some custom plug-ins to your editor. You can read about how to create a plugin in TinyMCE Wiki article.

Adding a custom plugin also requires a few steps to take. Though, the procedure is very similar to adding a configuration file.

This is what you need to add a plugin:

- Create a .properties file and put the name of the plug-in and a path to it into the file. The file can contain multiple plug-in declarations. Your .properties file should be like this.

  Example:

      ...

      pluginName=/mytinymceplugins/plugin1Name/editor_plugin.js

      ...

- Use the "customPlugins" attribute to specify the .properties file with a plugin name and a path to it.

  If your .properties file is named "myPlugins", then your will have this code on the page.

  Example:

      ...

      <rich:editor theme="advanced" customPlugins="myPlugins" plugins="pluginName" />

      ...

## Note:

Some plug-ins which available for download might have some dependencies on TinyMCE scripts. For example, dialog pop-ups require tiny_mce_popup.js script file. Assuming that you will not plug custom plugins to the RF jar with editor component (standard TinyMCE plugins creation implies that plugins are put into TinyMCE's corresponding directory) you should manually add required TinyMCE scripts to some project folder and correct the js includes.

The implementation of the <rich:editor> component has two methods for handling events.

The attributes take some function name as a value with is triggered on the appropriate event. You need to use standard JavaScript function calling syntax.

- Using attributes ( "onchange" , "oninit" , "onsave" , "onsetup" )

  Example:

      ...

      <rich:editor value="#{bean.editorValue}" onchange="myCustomOnChangeHandler()" />

      ...

- Using <f:param> as a child element defining the "name" attribute with one of the TinyMCE's callbacks and the "value" attribute takes the function name you want to be called on the corresponding event as the value. Note, that the syntax in this case is a bit different: parentheses are not required.

  Example:

      ...

      <rich:editor value="#{bean.editorValue}">

              <f:param name="onchange" value="myCustomOnChangeHandler" />

      </rich:editor>

      ...

The <rich:editor> component has a build-in converter that renders HTML code generated by the editor to Seam text (you can read more on Seam in Seam guide.), it also interprets Seam text passed to the <rich:editor> and renders it to HTML. The converter can be enable with the "useSeamText" attribute.

Example:

This HTML code generated by editor

    ...

    <p><a href="http://mysite.com">Lorem ipsum</a> <i>dolor sit</i> amet, ea <u>commodo</u> consequat.</p>

    ...

will be parsed to the following Seam text:

    ...

    [Lorem ipsum=>http://mysite.com] *dolor sit* amet, ea _commodo_ consequat.

    ...

Accordingly, if the Seam text is passed to the component it will be parsed to HTML code.

#### 6.11.4.4. Reference Data

Table of <rich:editor> attributes.

Table 6.175. Component Identification Parameters

Name | Value
--- | ---
component-type | org.richfaces.component.Editor
component-class | org.richfaces.component.html.Htmleditor
component-family | org.richfaces.component.Editor
renderer-type | org.richfaces.renderkit.html.EditorRenderer
tag-class | org.richfaces.taglib.EditorTag

Table 6.176. Style classes (selectors) with the corresponding skin parameters

Class (selector) name | Description | Skin Parameter | CSS properties mapped
--- | --- | --- | ---
.richfacesSkin a:hover, .richfacesSkin a:link, .richfacesSkin a:visited, .richfacesSkin a:active | Defines styles for links state | generalTextColor | color
.richfacesSkin table | Defines styles for the wrapper <table> element of the editor | additionalBackgroundColor | background
.richfacesSkin iframe | Defines styles for the editor text area | tableBackgroundColor | background
.richfacesSkin .mceExternalToolbar | Defines styles for the toolbar | panelBorderColor | border-color
.richfacesSkin table.mceLayout | Defines styles for the table layout | panelBorderColor | border-left-color, border-right-color
.richfacesSkin table.mceLayout tr.mceFirst td | Defines styles for the toolbar elements | panelBorderColor | border-top-color
.richfacesSkin table.mceLayout tr.mceLast td | Defines styles for the editor window | panelBorderColor | border-bottom-color
.richfacesSkin .mceIframeContainer | Defines styles for the editor container | panelBorderColor | border-top-color, border-bottom-color
.richfacesSkin .mceStatusbar | Defines styles for the status bar | generalFamilyFont | font-family
generalTextColor | color
.richfacesSkin a.mceButtonEnabled:hover | Defines styles for the editor buttons hovered | headerBackgroundColor | background-color
.richfacesSkin span.mceButtonLabel | Defines styles for the editor buttons labels | generalFamilyFont | font-family
.richfacesSkin .mceListBox .mceText | Defines styles for the list box | generalFamilyFont | font-family
panelBorderColor | border-color
tableBackgroundColor | background
.richfacesSkin table.mceListBoxEnabled:hover .mceText, .richfacesSkin .mceListBoxSelected .mceText | Define styles for the list box hovered, selected respectively | tableBackgroundColor | background
.richfacesSkin div.mceColorSplitMenu table | Defines styles for the wrapper <table> element of the popup element for color selecting | tableBackgroundColor | background
panelBorderColor | border-color
.richfacesSkin .mceColorSplitMenu a | Defines styles for the items in the popup element for color selecting | panelBorderColor | border-color
.richfacesSkin .mceColorSplitMenu a.mceMoreColors | Defines styles for the "More Colors" button | panelBorderColor | border-color
generalFamilyFont | font-family
.richfacesSkin .mceColorSplitMenu a.mceMoreColors:hover | Defines styles for the "More Colors" button hovered | panelBorderColor | border-color
additionalBackgroundColor | background-color
.richfacesSkin a.mceMoreColors:hover | Defines styles for the "More Colors" button hovered | headerBackgroundColor | border-color
.richfacesSkin .mceColorPreview | Defines styles for the color preview | tableBorderColor | background
.richfacesSkin .mceMenu | Defines styles for the menus | panelBorderColor | border-color
.richfacesSkin .mceMenu table | Defines styles for the wrapper <table> element of the menu | tableBackgroundColor | background
.richfacesSkin .mceMenu .mceText | Defines styles for the menus labels | generalFamilyFont | font-family
generalTextColor | color
.richfacesSkin .mceMenu .mceMenuItemActive | Defines styles for the active menu items | additionalBackgroundColor | background-color
.richfacesSkin .mceMenu .mceMenuItemEnabled a:hover | Defines styles for the enabled menu items hovered | additionalBackgroundColor | background-color
.richfacesSkin td.mceMenuItemSeparator | Defines styles for the menu items separator | panelBorderColor | background
.richfacesSkin .mceMenuItemTitle a | Defines styles for the titles of the menu items | additionalBackgroundColor | background
panelBorderColor | border-bottom-color
.richfacesSkin .mceMenuItemDisabled .mceText | Defines styles for the disabled menu items | tabDisabledTextColor | color
.richfacesSkin .mceBlocker | Defines styles for the editor blocker | tableBackgroundColor | background
.richfacesSkin .mcePlaceHolder | Defines styles for the editor place holder | tableBorderColor | border-color

Table 6.177. Style classes (selectors) without skin parameters

Class name | Description
--- | ---
.richfacesSkin table.mceToolbar | Defines styles for the rows of icons within toolbar
.richfacesSkin .mceToolbar .mceToolbarStart span | Defines styles for the icon of the toolbar start element
.richfacesSkin .mceToolbar .mceToolbarEnd span | Defines styles for the icon of the toolbar end element
.richfacesSkin .mceIcon | Defines styles for the icons of the toolbar buttons
.richfacesSkin .mceButton | Defines styles for the buttons
.richfacesSkin .mceSeparator | Defines styles for the buttons separator
.richfacesSkin .mceButtonDisabled .mceIcon | Defines styles for the icons of the disabled buttons
.richfacesSkin .mceListBox .mceOpen | Defines styles for the icons of the list box "Open" button
.richfacesSkin .mceSplitButton a.mceOpen | Defines styles for the icons of the split buttons for color selecting
.richfacesSkin .mceSplitButton span.mceAction | Defines styles for the icons of the split buttons
.richfacesSkin .mceMenuItemSelected .mceIcon | Defines styles for the icons of the selected menu items
.richfacesSkin .mceNoIcons .mceMenuItemSelected a | Defines styles for the selected menu items without no icons
.richfacesSkin .mceMenuItemSub a | Defines styles for the icon of the submenu item
.richfacesSkin .mceProgress | Defines styles for the editor progress icon
.richfacesSkin .mceStatusbar a.mceResize | Defines styles for the resize button

You can find all necessary information about style classes redefinition in Definition of Custom Style Classes section.

#### 6.11.4.5. Relevant Resources Links

The <rich:editor> is based on TinyMCE editor and supports almost all its features and properties some of which are not described here since you can find more detailed documentation on them on the official web site.

On RichFaces LiveDemo page you can see an example of <rich:editor> usage and sources for the given example.

- Prev6.11.3. < rich:comboBox > ...
- Top of page
- Front page
- Next6.11.5. < rich:fileUpload > ...