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="[&]{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="[&]{3, 50}" />
</p:inputText>
]]>
but my inputText doesn't appear anymore.
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&
,<
and>
when they're supposed to be interpreted as-is.(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
&
becomes&
again.Update as per your update, the space in
{3, 50}
is causing the regex syntax error. Remove it.Using CDATA blocks around the JSF component is not the right solution at all. It would XML-escape the entire content, resulting in
<p:inputText>
being emitted plain vanilla instead of the component's HTML representation.Use the CDATA tag to escape the ampersand (&) symbol:
If you want to escape ampersand, lt (<) and gt (>) symbols in Javascript, add the CDATA section in Javascript but comment it:
Does a quoted string check help ?
'&'