Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unequal sign ("<") in javascript within a xthml file for jsf raises error (in netbeans) [duplicate]

Possible Duplicate:
javax.servlet.ServletException: Error Parsing /page.xhtml: The content of elements must consist of well-formed character data or markup

This is a jsf 2.0 project.

The xhtml file:

<?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">
    <h:head>
        <title>Ring</title>
        <h:outputScript library="js" name="jquery-1.8.1.min.js" />
        <h:outputScript library="js" name="processing-1.4.1.js" />

        <script type="text/javascript">
            $(function(){
                var pjs = Processing.getInstanceById("viz");
                var json = #{TableMatchesBean.json};
                var data = eval("("+json+")");
                if(data) {

                    for(i=0; i<data.segments.length; i++) {
                        var segment = data.segments[i];
                        pjs.addSegment(segment.label, segment.count,segment.isMain);
                    }
                }
            }); //end ready
        </script>

    </h:head>
    <h:body>

        <canvas id ="viz" data-processing-sources="common.pde"></canvas>

    </h:body>
</html>

On the first line of the for loop in the javascript,

for(i=0; i<data.segments.length; i++) {

Netbeans raises this error: "Fatal Error: Element type "data.segments.length" must be followed by either attribute specifications, ">" or "/>"."

This error suggests that the "<" is interpreted as some xhtml, not as js (I think). Is it a mistake by Netbeans or is there really a confusion between js and xhtml here?

like image 380
seinecle Avatar asked Dec 02 '22 21:12

seinecle


1 Answers

Move JavaScript code to an external JavaScript file

or

Use CDATA

<script type="text/javascript">
 //<![CDATA[
  var i = 0;

  while  (++i < 10)
  {
    // ...
  }
 //]]>
</script>
like image 134
epascarello Avatar answered Dec 10 '22 11:12

epascarello