Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to test inputText field to see if its content matches anything but at least one & (ampersand).

When I test & or & or \& inside pattern field of validateRegex, I always received this error :

javax.faces.view.facelets.FaceletException: Error Parsing /index.xhtml: Error Traced[line: 71] Le nom de l'identité doit immédiatement suivre le caractère "&" dans la référence d'entité.

and I get 500 error...

How can I escape this character?


Update

I have tested

<p:inputText id="player_name_register" value="#{login.name}">
    <f:validateRegex pattern="[&amp;]{3, 50}" />
</p:inputText>

But when I test with &&&&&& it doesn't work.

I also tested

<![CDATA[
    <p:inputText id="player_name_register" value="#{login.name}">
        <f:validateRegex pattern="[&amp;]{3, 50}" />
    </p:inputText>
]]>

but my inputText doesn't appear anymore.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
758 views
Welcome To Ask or Share your Answers For Others

1 Answer

Facelets is a XML based view technology. The whole view has to be syntactically valid XML. XML special characters like &, < and > needs to be escaped as &amp;, &lt; and &gt; when they're supposed to be interpreted as-is.

<f:validateRegex pattern="...&amp;..." />

(here, the ... represents the remainder of your regex)

A CDATA block won't work as it basically escapes the entire content, including JSF components. Quoting the escaped XML character makes no sense. After being parsed by the Facelets XML parser, the &amp; becomes & again.


Update as per your update, the space in {3, 50} is causing the regex syntax error. Remove it.

<p:inputText id="player_name_register" value="#{login.name}">
    <f:validateRegex pattern="[&amp;]{3,50}" />
</p:inputText>

Using CDATA blocks around the JSF component is not the right solution at all. It would XML-escape the entire content, resulting in &lt;p:inputText&gt; being emitted plain vanilla instead of the component's HTML representation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...