JSF,validateRegex和& (“&"号) [英] JSF, validateRegex and & (ampersand)

查看:54
本文介绍了JSF,validateRegex和& (“&"号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要测试inputText字段,以查看其内容是否与除至少一个& ;; (&"号).

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

当我在validateRegex的模式字段中测试&\&\\&时,我总是收到此错误:

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

javax.faces.view.facelets.FaceletException:错误解析/index.xhtml:跟踪错误[行:71]对身份的确认与否&" dans laréférenced'entité.

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é.

我得到500错误...

and I get 500 error...

我怎样才能逃脱这个角色?

How can I escape this character?

更新

我已经测试过

<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.

我也测试过

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

但是我的inputText不再出现.

but my inputText doesn't appear anymore.

推荐答案

Facelets是一种基于XML的视图技术.整个视图必须是语法上有效的XML. XML特殊字符(如&<>)需要转义当应按原样解释时,它们为&amp;&lt;&gt;.

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)

CDATA块将无法正常工作,因为它基本上会转义包括JSF组件在内的整个内容.引用转义的XML字符没有任何意义.在经过Facelets XML解析器解析后,&amp;再次变为&.

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.

更新,根据您的更新,{3, 50}中的空格导致正则表达式语法错误.删除它.

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>

在JSF组件周围使用CDATA块根本不是正确的解决方案.它将对所有内容进行XML转义,从而导致&lt;p:inputText&gt;发出纯香草味,而不是组件的HTML表示.

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.

这篇关于JSF,validateRegex和&amp; (“&"号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆