我们项目的目标之一,即DDA要求很高,是为了确保呈现的HTML 100%符合xhtml 1.0过渡语法。可悲的是,我有一个我无法消除的错误。这是因为JSF将以下javaScript片段注入到页面中(为了清晰起见而格式化),因为它没有包含在CDATA中,所以w3c验证器会拒绝此消息:
Line 443, Column 122: character "<" is the first character of a delimiter but occurred as data
…dp;if (adp != null) {for (var i = 0;i < adp.length;i++) {f.removeChild(adp[i])…
?
This message may appear in several cases:
You tried to include the "<" character in your page: you should escape it as "<"
You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.
Another possibility is that you forgot to close quotes in a previous tag.
我的问题是,是否可以让JSF将脚本块包装在CDATA中或者将脚本外部化?
<script type="text/javascript" language="Javascript">
function dpf(f) {
var adp = f.adp;
if (adp != null) {
for (var i = 0;i < adp.length;i++) {
f.removeChild(adp[i]);
}}};
function apf(f, pvp) {
var adp = new Array();
f.adp = adp;
var ps = pvp.split(',');
for (var i = 0,ii = 0;i < ps.length;i++,ii++) {
var p = document.createElement("input");p.type = "hidden";p.name = ps[i];p.value = ps[i + 1];
f.appendChild(p);
adp[ii] = p;i += 1;
}};
function jsfcljs(f, pvp, t) {
apf(f, pvp);
var ft = f.target;
if (t) {
f.target = t;
}
f.submit();
f.target = ft;dpf(f);
};
</script>
答案 0 :(得分:2)
如果不编辑JS文件本身就不可能。
提取jsf-impl.jar
文件,将com/sun/faces/sunjsf.js
文件复制到完全相同的包结构中的webapp项目中,即作为sunjsf.js
包内的com.sun.faces
文件。将<
修改为<
并保存。
或者,您也可以使用已编辑的JS文件重建JAR文件本身。
答案 1 :(得分:1)
尝试像这样更改脚本块
<script type="text/javascript">
//<[!CDATA[
...your code here
//]]>
</script>
这应该使验证器解析器忽略整个脚本块:如果您的代码源包含大于(&gt;)的字符,则小于(&lt;),您必须将它放在CDATA
分隔符中才能生成它经过验证。