Class HtmlStringTrimConverter

  • All Implemented Interfaces:
    javax.faces.convert.Converter<String>

    public class HtmlStringTrimConverter
    extends Object
    implements javax.faces.convert.Converter<String>
    A converter that trims empty HTML strings to the empty string. Useful e.g. for rich text editors that may return HTML such strings such as <p></p> that represent no content.

    It is quite hard to define what an empty HTML string is. For example, <p class="foo"></p> has no text content, but it does have a class attribute that may be used by CSS or JavaScript. This converter considers the following HTML strings as empty:

    • When the value is null, null is returned. If the string is empty or blank, it is considered empty. Otherwise, the strings is considered empty if all of the following hold:
    • The string is a valid HTML string.
    • The text content of the HTML is empty or blank.
    • All nodes in the DOM tree contain no attributes, except for possibly style.
    Since:
    8.2.0
    • Constructor Detail

      • HtmlStringTrimConverter

        public HtmlStringTrimConverter()
    • Method Detail

      • getAsObject

        public String getAsObject​(javax.faces.context.FacesContext context,
                                  javax.faces.component.UIComponent component,
                                  String value)
        Specified by:
        getAsObject in interface javax.faces.convert.Converter<String>
      • getAsString

        public String getAsString​(javax.faces.context.FacesContext context,
                                  javax.faces.component.UIComponent cmp,
                                  String value)
        Specified by:
        getAsString in interface javax.faces.convert.Converter<String>