4

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?

Community
  • 1
  • 1
seinecle
  • 10,118
  • 14
  • 61
  • 120
  • The question is: does it work when you run the app? If it does, then is Netbeans jsp/jsf editor who is unable to identify JS blocks inside the document. – Alfabravo Sep 06 '12 at 20:52
  • NITPICK: Use jQuery's [parseJSON](http://api.jquery.com/jQuery.parseJSON/) instead of eval. – epascarello Sep 06 '12 at 20:55

1 Answers1

17

Move JavaScript code to an external JavaScript file

or

Use CDATA

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

  while  (++i < 10)
  {
    // ...
  }
 //]]>
</script>
epascarello
  • 204,599
  • 20
  • 195
  • 236