I am new to Javascript and Java Server Faces and I am having the next Problem.
The Code below is working ok:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript">
function initialize()
{
alert("Testing");
}
</script>
</head>
<body onload="initialize()">
<h1 align="center">Sol-Tech</h1><br />
</body>
</html>
But when I add a FOR loop, it doesn’t work:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript">
function initialize()
{
for(var i; i<3; i++)
{
alert("Test");
}
}
</script>
</head>
<body onload="initialize()">
<h1 align="center">Sol-Tech</h1><br />
</body>
</html>

Has anyone any suggestion on how to perform a FOR loop in javascript without getting an error?
Thanks in advance,
Emanuel
You’re using an outdated version of Mojarra which exposes a bug wherein this kind of
IllegalArgumentException: null sourceis incorrectly been thrown when the view file contains a XML syntax error or when the view couldn’t be restored. See also java.lang.IllegalArgumentException: null source and JSF issue 1762.If you upgrade to a newer Mojarra version (currently already 2.1.14), then you’ll in this particular case get a more self-explaining XML syntax error on the character
<which indicates the start of a XML element. Facelets is namely a XML based view technology and parsed by a SAX parser. You’d need to replace the XML special character<by<or to put the whole script in a
CDATAblockor to just put it in its own
.jsfile so that it won’t be parsed as XML.See also:
Unrelated to the concrete problem, the JS syntax error (uninitialized
var iwhich I’ve already fixed in code snippets) is actually a completely different problem and would only show an error in client side in browser’s JS console and definitely not cause an exception in the server side as JS doesn’t run in webserver at all, but only in webbrowser.