最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JSF facelet page doesn't javascript string with '&' character - Stack Overflow

programmeradmin3浏览0评论

in a JSF facelet page (.xhtml) I have this javascript code

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

It doesn't work because the jfs engine think that "&box" is relative to a bindign, and it says:

Error Parsing /Box/ListaRichieste.xhtml: Error Traced[line: 20] The reference to entity "box" must end with the ';' delimiter

I can I avoid this behaviour?

in a JSF facelet page (.xhtml) I have this javascript code

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

It doesn't work because the jfs engine think that "&box" is relative to a bindign, and it says:

Error Parsing /Box/ListaRichieste.xhtml: Error Traced[line: 20] The reference to entity "box" must end with the ';' delimiter

I can I avoid this behaviour?

Share Improve this question edited Aug 22, 2011 at 17:07 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Aug 22, 2011 at 17:01 themarcuzthemarcuz 2,5836 gold badges36 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

Facelets is a XML based view technology. The & is a XML special character. It's interpreted as start of a XML entity like &nbsp;, &#160;, etc. It is therefore looking for the end character ;, but it found none, so it is throwing this error.

To represent the & literally inside a XML document, you need to use &amp; instead of &.

window.location = "DettaglioRichiesta.xhtml?id=" + id + "&amp;box=" + box;

You can also just put that JS code in its own .js file which you include by <script src> so that you don't need to fiddle with XML special characters in the JS code.

<script type="text/javascript" src="your.js"></script>
发布评论

评论列表(0)

  1. 暂无评论