edze
edze

Reputation: 3015

JSF2.0 using '<' and '>' in embedded JavaScript

I develop a JSF-Page like this in Netbeans

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Facelet Title</title>
        ...

        <script type="text/javascript" language="JavaScript">

        function drawShape()
        {
            ...

            var length = shapeCollection.length;
            for (var i = 0; i < length; i++)
            {
               ...
            }
        }   
        </script>
    </h:head>
    <h:body onload="drawShape();">
        <canvas id="myDrawing" width="500" height="500">
            <p>Your browser doesn't support canvas.</p>
        </canvas>
    </h:body>
</html>

Now I get an error in this part for (var i = 0; i < length; i++)

if I replace < with != it works

How can I aviod this problem?

Upvotes: 1

Views: 3622

Answers (1)

Quentin
Quentin

Reputation: 943697

See the XHTML specification for Script and Style blocks.

You need to wrap your inline JS with CDATA markers.

Upvotes: 5

Related Questions