Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.11.4.  < rich:editor > available since 3.3.0

Table 6.380. rich : editor attributes

Attribute Name Description
autoResizeAttribute enables to get the Editor area to resize to the boundaries of the contents.
binding JSF: The attribute takes a value-binding expression for a component property of a backing bean
configurationAttribute defines configuration properties file name
converter JSF: Id 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
customPluginsAttribute defines property file name witch contains descriptors of custom plugins
dialogTypeAttribute defines how dialogs/popups should be opened. Default value is "modal"
heightAttribute defines height of component.
id JSF: Every 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
labelA localized user presentable name for this component.
languageAttribute defines Editor language
onchange DHTML: The client-side script method to be called when the editor content is modified by TinyMCE
oninitThe client-side script method to be called when the initialization of the editor instances is finished
onsaveThe client-side script method to be called when the editor content is extracted/saved
onsetupThe client-side script method to be called before the editor instances get rendered
pluginsAttribute defines Editor plugins
readonlyHTML: Attribute defines Editor is readonly
rendered JSF: If "false", this component is not rendered
required JSF: If "true", this component is checked for non-empty input
requiredMessageA ValueExpression enabled attribute which defines text of validation message to show, if a required field is missing
skinAttribute defines Editor skin
styleHTML: CSS style rules to be applied to the component
styleClass JSF: Assigns one or more space-separated CSS class names to the component. Corresponds to the HTML "class" attribute.
tabindexHTML: In visual mode the attribute works the same way as "tab_focus" TinyMCE's property the attribute enables you to specify an element ID to focus, when the TAB key is pressed . You can also use the special ":prev" and ":next" values that will then place the focus on an input element placed before/after the TinyMCE instance in the DOM. While in "source" mode the attribute works like standard HTML tabindex attribute.
themeAttribute defines Editor theme
useSeamTextAttribute defines if model value should be converted to Seam Text. Default value is "false"
validator JSF: 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
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
value JSF: The current value of this component
valueChangeListener JSF: Listener for value changes
viewModeAttribute defines if tinyMCE WYSIWYG should be disabled. Default value is "visual"
widthHTML: Attribute defines width of component.


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:

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:


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.





















On the screenshot there are CSS selectors that define styles for component elements.




In order to redefine styles for all <rich:editor> 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:


...
.richfacesSkin .mceButton {                                 
    
border: 1px solid red;             
}  
...

This is the result:


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

Example:


...
.myClass{  
    
margin-top: 20px;
}
...

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

Example:


<rich:editor value="#{bean.text}" styleClass="myClass"/>