Skip to content

showing error while using JavaScript in JSP with Struts 2

My JSP code:

<script>
<s:if test="hasActionErrors()">
       if ($("input[name=radio_workitem]:checked").length > 0) {
            $("#id_div_workitem_detail").show();
        }
    </s:if>
</s:if>

on s:if, JSP shows compile time error when hovering mouse on it (like spell error red line under s:if), shows msg "Syntax error on token "if", ( expected after this token"

although this code works fine. No problem.

My questions are:

  1. Why it shows error, although it works ?
  2. Is this good coding practice to write Struts tag in JavaScript ?

I m using eclipse Luna IDE.

Answer

why it shows error, although it works ?

It has a syntax error, although it might work but eclipse cannot validate its syntax.

is this good coding practice to write struts tag in javascript ?

javascript should be javascript, don’t mess up jsp code with javascript.

I m using eclipse Luna Ide.

Eclipse is a best free IDE available in the world. But it might have bugs or missing some features important to you.

<s:if test="hasActionErrors()">
    <script>
      if ($("input[name=radio_workitem]:checked").length > 0) {
	   $("#id_div_workitem_detail").show();
      }
    </script>
</s:if>