我们对DDA的要求很高的项目的目标之一是确保呈现的HTML与xhtml 1.0过渡语法100%兼容。不幸的是,我有一个我无法消除的错误。这是因为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 "&lt;"
    You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", 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>

最佳答案

不编辑JS文件本身是不可能的。

提取jsf-impl.jar文件,将com/sun/faces/sunjsf.js文件以完全相同的包结构复制到webapp项目中,即作为sunjsf.js包中的com.sun.faces文件。将<编辑为&lt;并保存。在类加载层次结构中,此文件将优先于JAR文件中的文件,因此将被代替使用。

另外,您也可以始终使用编辑后的JS文件重建JAR文件本身。

10-08 20:08