Announcement Announcement Module
Collapse
No announcement yet.
STS 2.3.3.M1 - Cannot use '&&' in Javascript if statement Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • STS 2.3.3.M1 - Cannot use '&&' in Javascript if statement

    Near the top of my jspx file, I have this block of code:

    <jsp:output omit-xml-declaration="yes"/>
    <script type="text/javascript">
    var displayedDivId = '';
    function displayDiv(divId) {
    var ele = document.getElementById(divId);
    ele.style.display = "block";
    if ((displayedDivId != '') && (displayedDivId!=divId)) {
    var showing = document.getElementById(displayedDivId);
    showing.style.display = "none";
    }
    displayedDivId = divId;
    }
    </script>

    The line "if ((displayedDivId != '') && (displayedDivId!=divId)) {" generates a Jasper exception. The problem is that the system is looking for an entity within a Javascript function, which is incorrect.

    This is an excerpt of the stack trace:

    ug 3, 2010 5:20:10 PM org.apache.catalina.core.ApplicationDispatcher invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    org.apache.jasper.JasperException: /WEB-INF/views/vocabulary/vocabularyMaintenance.jspx(9,35) The entity name must immediately follow the '&' in the entity reference.
    at org.apache.jasper.compiler.DefaultErrorHandler.jsp Error(DefaultErrorHandler.java:40)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatc h(ErrorDispatcher.java:407)
    at org.apache.jasper.compiler.ErrorDispatcher.jspErro r(ErrorDispatcher.java:88)
    at org.apache.jasper.compiler.JspDocumentParser.parse (JspDocumentParser.java:214)
    at org.apache.jasper.compiler.ParserController.doPars e(ParserController.java:239)
    at org.apache.jasper.compiler.ParserController.parseD irectives(ParserController.java:120)
    at org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:165)
    at org.apache.jasper.compiler.Compiler.compile(Compil er.java:332)

  • #2
    I don't know a way to tell Jasper not to evaluate the double ampersand, but you could use nested if statements to get rid of it:

    Code:
    if (displayedDivId != '') {
        if (displayedDivId!=divId) {
            var showing = document.getElementById(displayedDivId);
            showing.style.display = "none";
        }
    }
    This is not an ideal solution, but it might work in the meantime while you debug the real problem.

    Comment


    • #3
      Yes, I am now using nested "if" statements, but there are other places where Spring is inappropriately looking for entities where there is a "&" character and that needs to be fixed.

      Comment


      • #4
        The real problem is operator error (me). I did not realize the .jspx files require that the "&" character be replaced with "&amp;". For example, instead of this statement, which would fail in jspx:

        if ( (x!=null) && (x>5))

        one must use

        if ( (x!=null) &amp;&amp; (x>5))

        Comment


        • #5
          In the STS 2.3.3.M1 there is a bug. The '&&'cannot be used in a java script if statement in the jspx file. The code where the bug actually occurs is also given. It is near the top of the code in the jspx file. There is a line of code which contains an ampersand sign. That line generates an exception. The stack trace is also given to track the error. “Nested if” statements could be a solution for this problem.

          Comment


          • #6
            Originally posted by mkp View Post
            In the STS 2.3.3.M1 there is a bug. The '&&'cannot be used in a java script if statement in the jspx file. The code where the bug actually occurs is also given. It is near the top of the code in the jspx file. There is a line of code which contains an ampersand sign. That line generates an exception. The stack trace is also given to track the error. “Nested if” statements could be a solution for this problem.
            Try &amp; instead of & in jspx.

            Or you can try wrapping your Javascript code in the <![CDATA[.....]]> tag

            Comment

            Working...
            X