• 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

MarkText Matching

MarkText highlights search terms within specified containers using mark.js by Julien Royer. These examples compare the options that control how a search term matches the text.

MarkText Tag Documentation

MarkText highlights search terms within specified containers using mark.js.

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.
accuracy String false partially Search accuracy level: 'partially', 'complementarily', or 'exactly'.
acrossElements Boolean false false Search across element boundaries.
caseSensitive Boolean false false Whether the search should be case sensitive.
diacritics Boolean false true Whether accented and unaccented letters are treated as the same during matching.
exclude List false Array of exclusion selectors. Matches inside these elements will be ignored.
for String true Search expression to resolve the target component to search within.
iframes Boolean false false Whether matching should include same-origin iframe documents.
iframesTimeout Integer false 5000 Maximum wait time in milliseconds for iframe loading.
onDone String false Client-side callback executed after marking is complete. The callback receives totalMatches as a parameter.
separateWordSearch Boolean false true Whether to match each word separately.
style String false Inline style of the component.
styleClass String false Style class of the component.
synonyms Object false Map of synonyms for term matching.
value String true Search terms to highlight. Can be a string or array of strings.
wildcards String false disabled Wildcard matching mode: 'disabled'|'enabled'|'withSpaces'.
Tag Documentation Widget Source Basic Matching Search Terms Scope
Case Sensitivity

With caseSensitive="true" the search is case-sensitive; with false it is case-insensitive.

Search term:
Case Sensitive (caseSensitive=true)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Case Insensitive (caseSensitive=false)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Separate Word Search

With separateWordSearch="true" each word is searched separately; with false the exact phrase is searched.

Search term:
Separate Word Search (separateWordSearch=true)

This is a word search example. The word is here, and search is there. Word search together in this sentence.

Exact Phrase Search (separateWordSearch=false)

This is a word search example. The word is here, and search is there. Word search together in this sentence.

Accuracy Levels

accuracy="partially" matches if the search term is contained in the text, exactly only if the text equals the search term, complementarily if the search term contains the text.

Search term:
Partially (accuracy='partially')

ips sum ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Exactly (accuracy='exactly')

ips sum ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Complementarily (accuracy='complementarily')

ips sum ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Usage


<style>
    .marktext-highlight,
    mark {
        background-color: yellow !important;
        color: black !important;
    }
</style>

<div class="card">
    <h5>Case Sensitivity</h5>
    <p>With <code>caseSensitive="true"</code> the search is case-sensitive; with <code>false</code> it is case-insensitive.</p>
    <h:form id="formCaseSensitivity">
        <h:panelGrid columns="3" cellpadding="4">
            <h:outputText value="Search term:"/>
            <p:inputText id="searchInput" value="#{markTextController.searchTermCaseSensitivity}" placeholder="Enter search term">
                <p:ajax event="keyup" delay="500" update="caseSensitivePanel caseInsensitivePanel markTextCaseSensitive markTextCaseInsensitive"/>
            </p:inputText>
            <p:commandButton value="Highlight" update="caseSensitivePanel caseInsensitivePanel markTextCaseSensitive markTextCaseInsensitive" icon="pi pi-search"/>
        </h:panelGrid>

        <h:panelGrid columns="2" style="width: 100%">
            <p:panel id="caseSensitivePanel" header="Case Sensitive (caseSensitive=true)" style="margin-right: 10px">
                <h:panelGroup id="caseSensitiveContent" layout="block">
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                </h:panelGroup>
            </p:panel>

            <p:panel id="caseInsensitivePanel" header="Case Insensitive (caseSensitive=false)">
                <h:panelGroup id="caseInsensitiveContent" layout="block">
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                </h:panelGroup>
            </p:panel>
        </h:panelGrid>

        <pe:markText id="markTextCaseSensitive" for="caseSensitiveContent" value="#{markTextController.searchTermCaseSensitivity}" styleClass="marktext-highlight" caseSensitive="true"/>
        <pe:markText id="markTextCaseInsensitive" for="caseInsensitiveContent" value="#{markTextController.searchTermCaseSensitivity}" styleClass="marktext-highlight" caseSensitive="false"/>
    </h:form>
</div>

<div class="card">
    <h5>Separate Word Search</h5>
    <p>With <code>separateWordSearch="true"</code> each word is searched separately; with <code>false</code> the exact phrase is searched.</p>
    <h:form id="formSeparateWordSearch">
        <h:panelGrid columns="3" cellpadding="4">
            <h:outputText value="Search term:"/>
            <p:inputText id="searchInput" value="#{markTextController.searchTermSeparateWord}" placeholder="Enter search term">
                <p:ajax event="keyup" delay="500" update="separateWordPanel exactPhrasePanel markTextSeparateWord markTextExactPhrase"/>
            </p:inputText>
            <p:commandButton value="Highlight" update="separateWordPanel exactPhrasePanel markTextSeparateWord markTextExactPhrase" icon="pi pi-search"/>
        </h:panelGrid>

        <h:panelGrid columns="2" style="width: 100%">
            <p:panel id="separateWordPanel" header="Separate Word Search (separateWordSearch=true)" style="margin-right: 10px">
                <h:panelGroup id="separateWordContent" layout="block">
                    <p>This is a word search example. The word is here, and search is there. Word search together in this sentence.</p>
                </h:panelGroup>
            </p:panel>

            <p:panel id="exactPhrasePanel" header="Exact Phrase Search (separateWordSearch=false)">
                <h:panelGroup id="exactPhraseContent" layout="block">
                    <p>This is a word search example. The word is here, and search is there. Word search together in this sentence.</p>
                </h:panelGroup>
            </p:panel>
        </h:panelGrid>

        <pe:markText id="markTextSeparateWord" for="separateWordContent" value="#{markTextController.searchTermSeparateWord}" styleClass="marktext-highlight" separateWordSearch="true"/>
        <pe:markText id="markTextExactPhrase" for="exactPhraseContent" value="#{markTextController.searchTermSeparateWord}" styleClass="marktext-highlight" separateWordSearch="false"/>
    </h:form>
</div>

<div class="card">
    <h5>Accuracy Levels</h5>
    <p>
        <code>accuracy="partially"</code> matches if the search term is contained in the text, <code>exactly</code> only if the text
        equals the search term, <code>complementarily</code> if the search term contains the text.
    </p>
    <h:form id="formAccuracyLevels">
        <h:panelGrid columns="3" cellpadding="4">
            <h:outputText value="Search term:"/>
            <p:inputText id="searchInput" value="#{markTextController.searchTermAccuracy}" placeholder="Enter search term">
                <p:ajax event="keyup" delay="500" update="partiallyPanel exactlyPanel complementarilyPanel markTextPartially markTextExactly markTextComplementarily"/>
            </p:inputText>
            <p:commandButton value="Highlight" update="partiallyPanel exactlyPanel complementarilyPanel markTextPartially markTextExactly markTextComplementarily" icon="pi pi-search"/>
        </h:panelGrid>

        <h:panelGrid columns="3" style="width: 100%">
            <p:panel id="partiallyPanel" header="Partially (accuracy='partially')" style="margin-right: 10px">
                <h:panelGroup id="partiallyContent" layout="block">
                    <p>ips sum ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                </h:panelGroup>
            </p:panel>

            <p:panel id="exactlyPanel" header="Exactly (accuracy='exactly')" style="margin-right: 10px">
                <h:panelGroup id="exactlyContent" layout="block">
                    <p>ips sum ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                </h:panelGroup>
            </p:panel>

            <p:panel id="complementarilyPanel" header="Complementarily (accuracy='complementarily')">
                <h:panelGroup id="complementarilyContent" layout="block">
                    <p>ips sum ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                </h:panelGroup>
            </p:panel>
        </h:panelGrid>

        <pe:markText id="markTextPartially" for="partiallyContent" value="#{markTextController.searchTermAccuracy}" styleClass="marktext-highlight" accuracy="partially"/>
        <pe:markText id="markTextExactly" for="exactlyContent" value="#{markTextController.searchTermAccuracy}" styleClass="marktext-highlight" accuracy="exactly"/>
        <pe:markText id="markTextComplementarily" for="complementarilyContent" value="#{markTextController.searchTermAccuracy}" styleClass="marktext-highlight" accuracy="complementarily"/>
    </h:form>
</div>