JSF facelet页面不带有'&'字符的javascript字符串

the*_*cuz 5 javascript jsf facelets

在JSF facelet页面(.xhtml)中我有这个javascript代码

<script type="text/javascript">
        function navigateToDetail() {
            var id = document.getElementById("idElemento").value;
            alert(id);
            var isPratica = document.getElementById("isPratica").value;
            alert(isPratica);
            var box = "#{boxCtrl.idBox}";
            alert(box);             
            if (isPratica==true)
                window.location = "DettaglioRichiesta.xhtml?id=" + id + "&box=" + box;
            else
                window.location = "../Richieste/DettaglioRichiesta.xhtml?id=" + id + "&box=" + box;

        }
    </script>
Run Code Online (Sandbox Code Playgroud)

它不起作用,因为jfs引擎认为"&box"是相对于绑定的,它说:

Error Parsing /Box/ListaRichieste.xhtml: Error Traced[line: 20] The reference to entity "box" must end with the ';' delimiter
Run Code Online (Sandbox Code Playgroud)

我可以避免这种行为吗?

Bal*_*usC 14

Facelets是一种基于XML的视图技术.这&是一个XML特殊字符.它被解释为XML实体的开头,如&nbsp;,&#160;等等.因此它正在寻找结束字符;,但它没有找到,所以它抛出了这个错误.

要在&字面上表示XML文档,您需要使用&amp;而不是&.

window.location = "DettaglioRichiesta.xhtml?id=" + id + "&amp;box=" + box;
Run Code Online (Sandbox Code Playgroud)

您也可以将JS代码放在自己.js包含的文件中,<script src>这样您就不需要在JS代码中使用XML特殊字符.

<script type="text/javascript" src="your.js"></script>
Run Code Online (Sandbox Code Playgroud)