• 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

Converters

PrimeFaces Extensions has built-in converters: pe:convertJson and pe:convertGson convert values to and from JSON, pe:convertLocale converts a locale string to a java.util.Locale and pe:sanitizer sanitizes input with an OWASP HTML policy.

ConvertJson Tag Documentation

Converter to convert JSON.

NameTypeRequiredDefaultDescription
type String false Data type of the value object (optional). Any primitive type, array, non-generic or generic type is supported. Data type is sometimes required to convert a value to a JSON representation. All data types should be fully qualified. Default is null.

ConvertLocale Tag Documentation

Converter to convert an ISO Locale.

NameTypeRequiredDefaultDescription
separator Character false _ Character which will be used to separate the country and language.

Sanitizer Tag Documentation

Converter to sanitize HTML with an OWASP PolicyFactory.

NameTypeRequiredDefaultDescription
decodeHtml boolean false true Run input through OWASP HTML Decoder.
policy PolicyFactory false strict An instance of OWASP PolicyFactory which declares how to sanitize the input.

ConvertGson Tag Documentation

Converter to convert JSON using GSON.

NameTypeRequiredDefaultDescription
type String false Data type of the value object (optional). Any primitive type, array, non-generic or generic type is supported. Data type is sometimes required to convert a value to a JSON representation. All data types should be fully qualified. Default is null.
Tag Documentation
JsonConverter with pe:remoteCommand

JsonConverter applied to a RemoteCommand: attach pe:convertJson to pe:assignableParam. The JavaScript objects are sent as JSON and converted to a Circle bean.



- - -

JsonConverter with f:viewParam and URL parameters

JsonConverter sets a value from a URL request parameter into a bean with f:viewParam and pe:convertJson. Use RequestParameterBuilder to build URL parameters in JSON representation. This pre-initializes forms with default values passed in the URL on the initial page load (GET request). The demo covers primitives, arrays, simple types, java.util.Date, parametrized collections and maps, and generic and non generic classes. Click "Open Link" there to see the URL parameters set into the bean. URLs longer than 2083 characters may not work in old browsers.

Show JsonConverter with f:viewParam
LocaleConverter

The LocaleConverter (pe:convertLocale) converts a locale string (for example de_DE) to a java.util.Locale object and back.

Enter a new locale here (a valid locale is for example de_DE):
Available locales:
SanitizingConverter

The SanitizingConverter (pe:sanitizer) sanitizes any input using an OWASP Java HTML Sanitizer PolicyFactory. It is useful for cleansing input that is displayed in an h:outputText with escape="false".

Enter text including HTML tags to see the default policy:

Custom policy allows HTML tags including <i> and <strong>:

Lenient converter allows <i> and <strong>:

Italic

JSON data types

pe:convertJson has one optional attribute type which specifies the data type of the value object. Any primitive type, array, non generic or generic type is supported. The data type is sometimes required to convert a value to or from its JSON representation. All data types should be fully qualified. Examples:

  • boolean
  • int
  • long[]
  • java.lang.String
  • java.util.Date
  • java.util.Collection<java.lang.Integer>
  • java.util.Map<java.lang.String, com.prime.FooPair<java.lang.Integer, java.util.Date>>
  • com.prime.FooNonGenericClass
  • com.prime.FooGenericClass<java.lang.String, java.lang.Integer>
  • com.prime.FooGenericClass<int[], com.prime.FooGenericClass<com.prime.FooNonGenericClass, java.lang.Boolean>>

The tag documentation shows convertJson, convertLocale, sanitizer and convertGson (the Gson based alternative to convertJson); sanitizerLenient is the lenient variant of sanitizer.

Usage


<div class="card">
    <h5>JsonConverter with pe:remoteCommand</h5>
    <p>JsonConverter applied to a RemoteCommand: attach <code>pe:convertJson</code> to <code>pe:assignableParam</code>. The JavaScript objects are sent as JSON and converted to a <code>Circle</code> bean.</p>
    <h:form id="formJsonRemoteCommand">
        <p:growl id="growl" showDetail="true"/>

        <pe:remoteCommand id="applyDataCommand" name="applyData" process="@this" update="subject date circle growl"
                          actionListener="#{remoteCommandController.parametersAssigned}">

            <pe:assignableParam name="subject" assignTo="#{remoteCommandController.subject}"/>
            <pe:assignableParam name="date" assignTo="#{remoteCommandController.date}">
                <f:convertDateTime type="both" pattern="MM/dd/yyyy HH:mm:ss"/>
            </pe:assignableParam>
            <pe:assignableParam name="circle" assignTo="#{remoteCommandController.circle}">
                <pe:convertJson/>
            </pe:assignableParam>
        </pe:remoteCommand>

        <h:outputLabel for="subject" value="Subject: "/>
        <h:outputText id="subject" value="#{remoteCommandController.subject}"/>
        <br/>
        <h:outputLabel for="date" value="Date: "/>
        <h:outputText id="date" value="#{remoteCommandController.date}"/>
        <br/>
        <h:outputLabel for="circle" value="Circle: "/>
        <h:outputText id="circle"
                      value="#{remoteCommandController.circle.radius} - #{remoteCommandController.circle.backgroundColor} - #{remoteCommandController.circle.borderColor} - #{remoteCommandController.circle.scaleFactor}"/>
        <br/><br/>

        <p:commandButton value="Apply Data" type="button" onclick="applyData('hello world', '05/14/2007 12:55:42', JSON.stringify(circle))"/>
        <p:commandButton value="Apply Second Data" type="button" onclick="applyData('hello user', '07/11/2001 11:55:42', JSON.stringify(circle2))"/>
    </h:form>

    <script>
        circle = {
            radius: 50,
            backgroundColor: "#FF0000",
            borderColor: "#DDDDDD",
            scaleFactor: 1.2
        };
        circle2 = {
            radius: 32,
            backgroundColor: "#FF0320",
            borderColor: "#DDFFFD",
            scaleFactor: 1.6
        };
    </script>
</div>

<div class="card">
    <h5>JsonConverter with f:viewParam and URL parameters</h5>
    <p>JsonConverter sets a value from a URL request parameter into a bean with <code>f:viewParam</code> and <code>pe:convertJson</code>. Use <code>RequestParameterBuilder</code> to build URL parameters in JSON representation. This pre-initializes forms with default values passed in the URL on the initial page load (GET request).
        The demo covers primitives, arrays, simple types, <code>java.util.Date</code>, parametrized collections and maps, and generic and non generic classes. Click "Open Link" there to see the URL parameters set into the bean. URLs longer than 2083 characters may not work in old browsers.</p>
    <p:linkButton value="Show JsonConverter with f:viewParam" icon="pi pi-external-link" target="_blank"
                  href="#{request.contextPath}/ui/input/converters/standalone/viewParam"/>
</div>

<div class="card">
    <h5>LocaleConverter</h5>
    <p>The LocaleConverter (<code>pe:convertLocale</code>) converts a locale string (for example <code>de_DE</code>) to a <code>java.util.Locale</code> object and back.</p>
    <h:form id="formLocaleConverter">
        <p:messages id="messages"/>

        Enter a new locale here (a valid locale is for example de_DE):<br/>
        <p:inputText id="enteredLocale" value="#{localeController.enteredLocale}" required="true">
            <pe:convertLocale/>
        </p:inputText>

        <h:panelGroup layout="block" style="margin-top: 10px;margin-bottom: 10px;">
            <p:commandButton value="Add" action="#{localeController.add}" update="messages addedLocales enteredLocale"/>
        </h:panelGroup>

        Available locales:<br/>
        <h:selectManyListbox id="addedLocales" value="#{localeController.selectedLocales}" style="width: 200px;">
            <pe:convertLocale/>
            <f:selectItems value="#{localeController.addedLocales}"/>
        </h:selectManyListbox>
    </h:form>
</div>

<div class="card">
    <h5>SanitizingConverter</h5>
    <p>The SanitizingConverter (<code>pe:sanitizer</code>) sanitizes any input using an OWASP Java HTML Sanitizer <code>PolicyFactory</code>. It is useful for cleansing input that is displayed in an <code>h:outputText</code> with <code>escape="false"</code>.</p>
    <h:form id="formSanitizingConverter">
        <p:messages id="messages"/>

        <h:panelGroup id="timePickerGroup" layout="block">
            <p>
                Enter text including HTML tags to see the default policy:
                <p:inputText id="defaultSanitizer" value="#{sanitizingController.defaultSanitizer}">
                    <pe:sanitizer/>
                </p:inputText>
            </p>

            <p>
                Custom policy allows HTML tags including &lt;i&gt; and &lt;strong&gt;:
                <p:inputText id="customSanitizer" value="#{sanitizingController.customSanitizer}">
                    <pe:sanitizer decodeHtml="true" policy="#{sanitizingController.policyFactory}"/>
                </p:inputText>
            </p>

            <p>
                Lenient converter allows &lt;i&gt; and &lt;strong&gt;:
                <h:outputText id="lenientSanitizer" escape="false" converter="primefaces.SanitizingLenientConverter" value="#{sanitizingController.customSanitizer}"/>
            </p>
        </h:panelGroup>

        <h:panelGroup layout="block" style="margin-top: 10px;margin-bottom: 10px;">
            <p:commandButton value="Submit" update="messages defaultSanitizer customSanitizer lenientSanitizer"/>
        </h:panelGroup>
    </h:form>
</div>