• 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

MonacoEditor Basic

MonacoEditor is the code editor which powers VS Code, as a JSF component: inline (pe:monacoEditor) or in an iframe (pe:monacoEditorFramed).

MonacoEditor Tag Documentation

Inline Monaco code editor (no iframe).

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered Boolean false generated Unique identifier of the component in a namingContainer.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
extender String false Extender script: JavaScript expression that evaluates to an extender instance.
overflowWidgetsDomNode String false Search expression for a component; places overflow widgets inside an external DOM node.

MonacoEditorFramed Tag Documentation

Framed Monaco code editor (iframe).

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered Boolean false generated Unique identifier of the component in a namingContainer.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
extender String false URL to an extender script loaded into the iframe.
iframeUrlParams Object false Additional URL params added to the iframe URL. Either a Map<String, String> or a String with a JavaScript expression that evaluates to an object representing such a map.
Tag Documentation Widget Source Basic Localization Events Theme Extender Diff Diff Localization Diff Events Diff Theme Diff Extender
Basic Usage

MonacoEditor is fully updateable via AJAX as you can see with the select options below. It also keeps its scroll position during an AJAX update. Switch between the inline and the iframe variant of the editor.

Component variants

The Monaco Editor is the code editor which powers VS Code. It offers IntelliSense and validation for JavaScript/TypeScript, CSS/LESS/SCSS and JSON, syntax highlighting for many more languages, and comes with localization for a few major languages. This component is a wrapper that allows Monaco Editor to be used as a JSF component and comes in four varieties:

  • pe:monacoEditor renders the editor inline in the page. This is usually more efficient and the preferred way when you do not need different editors with a different global configuration.
  • pe:monacoEditorFramed renders the editor in an iframe for improved encapsulation. Part of the Monaco configuration is window global, such as the loaded TypeScript declaration files; use the framed variant for multiple editors with a completely different setup.
  • pe:monacoDiffEditor renders a diff editor for comparing two files inline in the page.
  • pe:monacoDiffEditorFramed renders a diff editor in an iframe.

All variants share almost the same API. The diff editor has additional properties for the settings of the original (left) editor. The framed variant is controlled with postMessage and its client-side API is therefore asynchronous (Promises). The client-side API is fully typed, see primefaces-monaco-global.d.ts and primefaces-monaco-module.d.ts. See also the official client-side API and the Monaco Editor repository (MIT License) by Microsoft.

Keep in mind that Monaco is not supported in mobile browsers or mobile web frameworks, and that the Promise API is required (every current browser supports it).

The editors follow the color scheme of the page: monacoColorScheme.js sets the theme vs-dark in dark mode while the configured theme is the default vs.

Languages

Basic support including syntax highlighting is available for the following languages (check the official docs, more languages may have been added in the meantime):

  • abap
  • aes
  • apex
  • azcli
  • bat
  • bicep
  • c
  • cameligo
  • clojure
  • coffeescript
  • cpp
  • csharp
  • csp
  • css
  • cypher
  • dart
  • dockerfile
  • ecl
  • elixir
  • flow9
  • freemarker2
  • freemarker2.tag-angle.interpolation-bracket
  • freemarker2.tag-angle.interpolation-dollar
  • freemarker2.tag-auto.interpolation-bracket
  • freemarker2.tag-auto.interpolation-dollar
  • freemarker2.tag-bracket.interpolation-bracket
  • freemarker2.tag-bracket.interpolation-dollar
  • fsharp
  • go
  • graphql
  • handlebars
  • hcl
  • html
  • ini
  • java
  • javascript
  • json
  • julia
  • kotlin
  • less
  • lexon
  • liquid
  • lua
  • m3
  • markdown
  • mdx
  • mips
  • msdax
  • mysql
  • objective-c
  • pascal
  • pascaligo
  • perl
  • pgsql
  • php
  • pla
  • plaintext
  • postiats
  • powerquery
  • powershell
  • proto
  • pug
  • python
  • qsharp
  • r
  • razor
  • redis
  • redshift
  • restructuredtext
  • ruby
  • rust
  • sb
  • scala
  • scheme
  • scss
  • shell
  • sol
  • sparql
  • sql
  • st
  • swift
  • systemverilog
  • tcl
  • twig
  • typescript
  • typespec
  • vb
  • verilog
  • xml
  • yaml

Usage


<style>
    .monacoEditorBox {
        border: 1px solid var(--p-content-border-color);
        min-width: 0;
    }
</style>
<h:outputScript library="js" name="monacoColorScheme.js"/>

<div class="card">
    <h5>Basic Usage</h5>
    <p>
        MonacoEditor is fully updateable via AJAX as you can see with the select options below. It also keeps its scroll position during an AJAX update. Switch between the inline and the iframe variant of the editor.
    </p>
    <h:form id="formBasicUsage">
        <p:messages id="messages" showSummary="true" showDetail="true"/>

        <p:selectOneButton id="type" value="#{monacoEditorController.type}" styleClass="monacoSync">
            <f:selectItem itemLabel="Inline" itemValue="inline" />
            <f:selectItem itemLabel="Iframe" itemValue="framed" />
            <p:ajax process="@form" update="@(.monacoSync)" />
        </p:selectOneButton>

        <h:panelGroup id="basicOptionsWrapper" layout="block" styleClass="monacoSync">

            <h:panelGrid id="basicOptions" rendered="#{monacoEditorController.type eq 'inline'}"
                columns="14" style="margin-bottom:10px" cellpadding="5"
            >
                <p:outputLabel for="language" value="Code language: " />
                <p:selectOneMenu id="language" value="#{monacoEditorController.language}" filter="true">
                    <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{monacoEditorController.languages}" />
                    <p:ajax listener="#{monacoEditorController.onLanguageChange}" process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectOneMenu>

                <p:outputLabel for="theme" value="Theme: " />
                <p:selectOneMenu id="theme" value="#{monacoEditorController.theme}">
                    <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{monacoEditorController.themes}" />
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectOneMenu>

                <p:outputLabel for="locale" value="Locale: " />
                <p:selectOneMenu id="locale" value="#{monacoEditorController.locale}" converter="omnifaces.SelectItemsConverter">
                    <f:selectItem itemLabel="(Default)" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{monacoEditorController.locales}" var="locale"
                        itemLabel="#{locale.displayName}" itemValue="#{locale}" />
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectOneMenu>

                <p:selectBooleanCheckbox id="required" value="#{monacoEditorController.required}">
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectBooleanCheckbox>
                <p:outputLabel for="required" value="Required" />

                <p:selectBooleanCheckbox id="disabled" value="#{monacoEditorController.disabled}">
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectBooleanCheckbox>
                <p:outputLabel for="disabled" value="Disabled" />

                <p:selectBooleanCheckbox id="readOnly" value="#{monacoEditorController.readOnly}">
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectBooleanCheckbox>
                <p:outputLabel for="readOnly" value="Read-only" />
            </h:panelGrid>

            <h:panelGrid id="basicOptionsFramed" rendered="#{monacoEditorController.type eq 'framed'}"
                columns="14" style="margin-bottom:10px" cellpadding="5"
            >
                <p:outputLabel for="languageFramed" value="Code language: " />
                <p:selectOneMenu id="languageFramed" value="#{monacoEditorController.languageFramed}" filter="true">
                    <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{monacoEditorController.languages}" />
                    <p:ajax listener="#{monacoEditorController.onLanguageChange}" process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectOneMenu>

                <p:outputLabel for="themeFramed" value="Theme: " />
                <p:selectOneMenu id="themeFramed" value="#{monacoEditorController.themeFramed}">
                    <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{monacoEditorController.themes}" />
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectOneMenu>

                <p:outputLabel for="localeFramed" value="Locale: " />
                <p:selectOneMenu id="localeFramed" value="#{monacoEditorController.localeFramed}" converter="omnifaces.SelectItemsConverter">
                    <f:selectItem itemLabel="(Default)" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{monacoEditorController.locales}" var="locale"
                        itemLabel="#{locale.displayName}" itemValue="#{locale}" />
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectOneMenu>

                <p:selectBooleanCheckbox id="requiredFramed" value="#{monacoEditorController.requiredFramed}">
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectBooleanCheckbox>
                <p:outputLabel for="requiredFramed" value="Required" />

                <p:selectBooleanCheckbox id="disabledFramed" value="#{monacoEditorController.disabledFramed}">
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectBooleanCheckbox>
                <p:outputLabel for="disabledFramed" value="Disabled" />

                <p:selectBooleanCheckbox id="readOnlyFramed" value="#{monacoEditorController.readOnlyFramed}">
                    <p:ajax process="monacoEditorWrapper" update="monacoEditorWrapper" />
                </p:selectBooleanCheckbox>
                <p:outputLabel for="readOnlyFramed" value="Read-only" />
            </h:panelGrid>
        </h:panelGroup>

        <h:panelGroup id="monacoEditorWrapper" layout="block" styleClass="monacoEditorBox monacoSync">

            <pe:monacoEditor id="monacoEditor" widgetVar="monacoEditorBasic"
                oninitialized="monacoFollowScheme.call(this)"
                rendered="#{monacoEditorController.type eq 'inline'}"
                value="#{monacoEditorController.value}"
                required="#{monacoEditorController.required}"
                disabled="#{monacoEditorController.disabled}"
                readonly="#{monacoEditorController.readOnly}"
                locale="#{monacoEditorController.locale}"
                placeholder="enter your code... (inline)"
                editorOptions="#{monacoEditorController.editorOptions}"
                width="100%" height="400px" autoResize="true" />

            <pe:monacoEditorFramed id="monacoEditorFramed" widgetVar="monacoEditorFramedBasic"
                oninitialized="monacoFollowScheme.call(this)"
                rendered="#{monacoEditorController.type eq 'framed'}"
                value="#{monacoEditorController.valueFramed}"
                required="#{monacoEditorController.requiredFramed}"
                disabled="#{monacoEditorController.disabledFramed}"
                readonly="#{monacoEditorController.readOnlyFramed}"
                locale="#{monacoEditorController.localeFramed}"
                placeholder="enter your code... (framed)"
                editorOptions="#{monacoEditorController.editorOptionsFramed}"
                width="100%" height="400px" autoResize="true" />

            <p:commandButton id="btnSubmit" value="Submit" icon="pi pi-save"
                rendered="#{monacoEditorController.type eq 'inline'}"
                process="monacoEditor" update="monacoEditor messages"
                actionListener="#{monacoEditorController.submitContent}" />

            <p:commandButton id="btnSubmitFramed" value="Submit" icon="pi pi-save"
                rendered="#{monacoEditorController.type eq 'framed'}"
                process="monacoEditorFramed" update="monacoEditorFramed messages"
                actionListener="#{monacoEditorController.submitContent}" />

        </h:panelGroup>
    </h:form>
</div>