• Settings
    • Locale
    • Change the locale of the datepicker, schedule and client side validation messages.

      Language
      English
      English
      English
      French
      German
      German
      German
      Italian
      Korean
      Spanish
      Catalan
      Dutch
      Portuguese
      Portuguese
      Arabic
      Arabic
      Bulgarian
      Bangla
      Bosnian
      Czech
      Greek
      Estonian
      Persian
      Finnish
      Danish
      Hindi
      Indonesian
      Icelandic
      Croatian
      Japanese
      Hungarian
      Hebrew
      Georgian
      Central Kurdish
      Khmer
      Kyrgyz
      Kazakh
      Lithuanian
      Latvian
      Malay
      Norwegian
      Polish
      Romanian
      Russian
      Slovak
      Slovenian
      Serbian
      Serbian
      Swedish
      Thai
      Turkish
      Ukrainian
      Uzbek
      Vietnamese
      Chinese
      Chinese
  • Resources

SunEditor

SunEditor is a lightweight, flexible, customizable WYSIWYG text editor for your web applications. Based on SunEditor by Yi JiHong. With the default theme auto the editor follows the color scheme of the page.

SunEditor Tag Documentation

SunEditor WYSIWYG editor component.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered boolean false true Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
widgetVar String false generated ('widget_' + componentClientId) Name of the client side widget.
accesskey String false Access key to transfer focus to the input element.
allowBlocks boolean false true Whether to allow blocks to be included when secure=true and the HTML is sanitized.
allowFormatting boolean false true Whether to allow formatting to be included when secure=true and the HTML is sanitized.
allowImages boolean false true Whether to allow images to be included when secure=true and the HTML is sanitized.
allowLinks boolean false true Whether to allow links to be included when secure=true and the HTML is sanitized.
allowMedia boolean false true Whether to allow audio/video to be included when secure=true and the HTML is sanitized.
allowStyles boolean false true Whether to allow styles to be included when secure=true and the HTML is sanitized.
allowTables boolean false true Whether to allow tables to be included when secure=true and the HTML is sanitized.
ariaDescribedBy String false Identifies the element(s) that describe the object, enhancing accessibility.
cols int false 0 Defines the number of columns in the text area.
converter Converter false EL expression resolves to a converter instance or literal converter ID defining a component converter.
converterMessage String false Custom message to display when conversion fails.
dir String false ltr Direction indication for text that does not inherit directionality.
disabled boolean false false Specifies that an element should be disabled.
extender String false The extender to use for the editor.
height String false auto Height of the editor.
immediate boolean false false When set true, process validations logic is executed at apply request values phase for this component.
inputmode String false Specifies the type of data expected in the input, aiding virtual keyboards.
label String false A localized user presentable name.
lang String false Specifies the language of the element's content.
localValueSet boolean false false Indicates whether the local value of the component has been set.
locale Object false Locale for the editor. Can be a string or java.util.Locale instance.
maxlength int false Integer.MIN_VALUE Defines the maximum number of characters allowed in the input.
mode String false classic The mode to use: 'classic', 'inline', etc.
onblur String false Fires when an element loses focus.
onchange String false Fires when the value of an element has been changed.
onclick String false Fires when a mouse click on the element.
oncontextmenu String false Script to execute when the context menu is triggered.
oncopy String false Script to execute when content is copied from the element.
oncut String false Script to execute when content is cut from the element.
ondblclick String false Fires when a mouse double-click on the element.
ondrag String false Script to execute when an element is dragged.
ondragend String false Script to execute at the end of a drag operation.
ondragenter String false Script to execute when a dragged element enters a valid drop target.
ondragleave String false Script to execute when a dragged element leaves a valid drop target.
ondragover String false Script to execute when a dragged element is over a valid drop target.
ondragstart String false Script to execute at the start of a drag operation.
ondrop String false Script to execute when a dragged element is dropped.
onfocus String false Fires when an element gets focus.
oninput String false Script to execute when the element receives user input.
oninvalid String false Script to execute when the element's value is invalid.
onkeydown String false Fires when a user is pressing a key.
onkeypress String false Fires when a user presses a key.
onkeyup String false Fires when a user releases a key.
onmousedown String false Fires when a mouse button is pressed down on an element.
onmousemove String false Fires when the mouse pointer is moving while it is over an element.
onmouseout String false Fires when the mouse pointer moves out of an element.
onmouseover String false Fires when the mouse pointer moves onto an element.
onmouseup String false Fires when a mouse button is released over an element.
onpaste String false Script to execute when content is pasted into the element.
onreset String false Script to execute when the form is reset.
onscroll String false Script to execute when the element is scrolled.
onsearch String false Script to execute when a search is performed.
onselect String false Script to execute when text is selected.
onwheel String false Script to execute when the mouse wheel is used.
placeholder String false Specifies a short hint describing the expected value of the input.
readonly boolean false false Specifies that an input field is read-only.
required boolean false false Marks component as required.
requiredMessage String false Custom message to display when the required validation fails.
role String false Defines the role of the element for accessibility purposes.
rows int false 0 Defines the number of rows in the text area.
secure boolean false true Secure the component with the HTML Sanitizer library on the classpath.
strictMode boolean false true Whether to use strict mode.
style String false Specifies an inline CSS style for an element.
styleClass String false Specifies one or more CSS class names for an element.
submittedValue Object false
tabindex String false Specifies the tab order of an element.
theme String false auto The theme to use: 'auto', 'default', 'dark', 'cobalt', 'cream', or 'midnight'.
title String false Specifies extra information about an element (displayed as a tooltip).
toolbar String false The toolbar to use for the editor.
valid boolean false true Indicates whether the input's value is valid.
validator Validator false A method expression referring to a method validating the input.
validatorMessage String false Custom message to display when validation fails.
value Object false Value of the component.
valueChangeListener ValueChangeListener false A method binding expression referring to a method for handling a valuchangeevent.
width String false 100% Width of the editor.
Tag Documentation Widget Source
Basic Usage

A WYSIWYG editor with a configurable toolbar. Change the mode, theme, locale and direction with AJAX; the paste, copy, cut, drop and save events are sent to the server. The theme Auto picks the light or dark theme from the page.

Dialog

A popular use case is an editor inside a PrimeFaces dialog. This example is for both demonstration and testing.

Extender

Use the extender attribute to extend the editor, here with the KaTeX math plugin (KaTeX CSS and JavaScript must be loaded). this is the widget and this.cfg its JSON configuration.

Usage


<div class="card">
    <h5>Basic Usage</h5>
    <p>
        A WYSIWYG editor with a configurable toolbar. Change the mode, theme, locale and direction with AJAX; the paste, copy, cut,
        drop and save events are sent to the server. The theme <i>Auto</i> picks the light or dark theme from the page.
    </p>
    <h:form id="formBasicUsage">
        <p:messages id="messages" showSummary="true" showDetail="true"/>

        <h:panelGrid columns="8" id="pnlDetails" styleClass="p-4">
            <p:outputLabel value="Mode:" for="@next" styleClass="mr-2"/>
            <p:selectOneMenu id="cboMode" value="#{basicSunEditorController.mode}" styleClass="w-12rem mr-2"
                             required="true">
                <f:selectItems value="#{basicSunEditorController.modes}"/>
                <p:ajax update="sunEditor"/>
            </p:selectOneMenu>

            <p:outputLabel value="Theme:" for="@next" styleClass="mr-2"/>
            <p:selectOneMenu id="cboTheme" value="#{basicSunEditorController.theme}" styleClass="w-12rem mr-2"
                             required="true">
                <f:selectItems value="#{basicSunEditorController.themes}"/>
                <p:ajax update="sunEditor"/>
            </p:selectOneMenu>

            <p:outputLabel value="Locale:" for="@next" styleClass="mr-2"/>
            <p:selectOneMenu id="cboLocale" value="#{basicSunEditorController.language}" styleClass="w-12rem mr-2"
                             required="true">
                <f:selectItems value="#{basicSunEditorController.languages}"/>
                <p:ajax update="sunEditor"/>
            </p:selectOneMenu>

            <p:outputLabel value="RTL:" for="@next" styleClass="mr-2"/>
            <p:selectBooleanCheckbox id="chkRtl" value="#{basicSunEditorController.rtl}" styleClass="mr-2">
                <p:ajax update="sunEditor"/>
            </p:selectBooleanCheckbox>
        </h:panelGrid>

        <pe:sunEditor id="sunEditor" widgetVar="sunEditorBasic" value="#{basicSunEditorController.html}"
                      mode="#{basicSunEditorController.mode}" dir="#{basicSunEditorController.rtl ? 'rtl' : 'ltr'}"
                      theme="#{basicSunEditorController.theme}" locale="#{basicSunEditorController.language}"
                      toolbar="[['font','fontSize','blockStyle'],['paragraphStyle','blockquote'], ['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript', 'removeFormat'],
                      '/'
                      ,['fontColor', 'backgroundColor', 'outdent', 'indent', 'align', 'hr', 'list', 'table'],
                       ['link', 'image', 'audio', 'video', 'fullScreen', 'showBlocks', 'codeView', 'preview', 'exportPDF', 'save']]">
            <p:ajax event="paste" listener="#{basicSunEditorController.onPaste}" update="messages"/>
            <p:ajax event="copy" listener="#{basicSunEditorController.onCopy}" update="messages"/>
            <p:ajax event="cut" listener="#{basicSunEditorController.onCut}" update="messages"/>
            <p:ajax event="drop" listener="#{basicSunEditorController.onDrop}" update="messages"/>
            <p:ajax event="save" listener="#{basicSunEditorController.onSave}" update="@this messages"/>
            <f:attribute name="widgetPostConstruct" value="widget.editor.onPaste = function (e, cleanData, maxCharCount) {console.log('onpaste event detected!'); };"/>
        </pe:sunEditor>
    </h:form>
</div>

<div class="card">
    <h5>Dialog</h5>
    <p>A popular use case is an editor inside a PrimeFaces dialog. This example is for both demonstration and testing.</p>
    <h:form id="formDialog">
        <p:messages id="messages" showSummary="true" showDetail="true"/>

        <h:panelGrid columns="6" id="pnlDetails" styleClass="p-4">
            <p:commandButton value="Open Dialog" type="button" icon="pi pi-external-link" onclick="PF('dlgSunEditor').show()"/>
        </h:panelGrid>

        <p:dialog header="Header" widgetVar="dlgSunEditor" minHeight="40" width="60vw" showEffect="fade" closable="true" closeOnEscape="true" modal="true">
            <pe:sunEditor id="sunEditor" widgetVar="sunEditorDialog" value="#{basicSunEditorController.htmlDialog}"
                          mode="classic" dir="#{basicSunEditorController.rtl ? 'rtl' : 'ltr'}"
                          theme="#{basicSunEditorController.theme}" locale="#{basicSunEditorController.language}"
                          toolbar="[['font','fontSize','blockStyle'],['paragraphStyle','blockquote'], ['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript', 'removeFormat'],
                      '/'
                      ,['fontColor', 'backgroundColor', 'outdent', 'indent', 'align', 'hr', 'list', 'table'],
                       ['link', 'image', 'audio', 'video', 'fullScreen', 'showBlocks', 'codeView', 'preview', 'exportPDF', 'save']]">
                <p:ajax event="save" listener="#{basicSunEditorController.onSave}" update="@this messages"/>
            </pe:sunEditor>
        </p:dialog>
    </h:form>
</div>

<div class="card">
    <h5>Extender</h5>
    <p>
        Use the <code>extender</code> attribute to extend the editor, here with the KaTeX math plugin (KaTeX CSS and JavaScript must be loaded).
        <code>this</code> is the widget and <code>this.cfg</code> its JSON configuration.
    </p>
    <h:form id="formExtender">
        <!-- Must load Katext CSS and JS (here using OmniFaces CDN handler) -->
        <h:outputStylesheet library="cdn" name="katex.css"/>
        <h:outputScript library="cdn" name="katex.js"/>

        <!-- Google Fonts can be used "Roboto", "Bruno Ace SC"
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />
        <link href="https://fonts.googleapis.com/css2?family=Bruno+Ace+SC&amp;family=Roboto&amp;display=swap" rel="stylesheet" />
        -->

        <pe:sunEditor id="sunEditor" widgetVar="sunEditorExtender" value="#{basicSunEditorController.html}"
                      theme="#{basicSunEditorController.theme}" extender="editorExtender" toolbar="[['font','fontSize','blockStyle'],['math']]">
        </pe:sunEditor>
    </h:form>

    <script type="text/javascript">
        function editorExtender() {
            // this = widget
            // this.cfg = JSON configuration
            this.cfg.katex = window.katex;
            this.cfg.font = ["Serif", "Sans-Serif", "Monospace", "Roboto", "Bruno Ace SC"];
            this.cfg.defaultStyle = "font-family:Serif;";
        };
    </script>
</div>