There is no javascript line with '&' character on JSF front page

on JSF front 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> 

This does not work, because the jfs engine thinks "& box" refers to the binding, and it says:

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

Can I avoid this behavior?

+4
source share
1 answer

Facelets is an XML-based viewing technology. & is a special XML character . It is interpreted as the beginning of an XML object, such as &nbsp; , &#160; etc. Therefore, he is looking for a finite character ; but did not find it, so it throws this error.

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

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

You can also just put this JS code in your own .js file, which you include <script src> so that you do not need to insert special XML characters in the JS code.

 <script type="text/javascript" src="your.js"></script> 
+12
source

All Articles