Reputation: 183
I'm having an issue with Eclipse where it's complaining about missing semicolons in javascript code in a jsp file. Given the two lines below, Eclipse complains about the first line and indicates that there's a missing semicolon right before the closing curly brace. It has no complaints about the second line. I'd prefer to use the first way, but I'm annoyed with the warnings. Is there a different syntax that I should be using? I'm also using JQuery, so I don't know if this is contributing to the parsing error in Eclipse.
var isFoo = ${actionBean.isFoo}; // javascript type is boolean
var isFoo = '${actionBean.isFoo}'; // javascript type is string
To answer some of the questions people have posed in the comments...
This code is from a JSP file and actionBean refers to the Java action bean for this page. "isFoo" is a member variable of the action bean. The syntax ${actionBean.isFoo} is JSP Expression Language (or EL for short) and it's used to evaluate a java variable in a JSP. In this case, my code takes the value from the java variable and assigns it to the javascript variable. The code works just fine, but Eclipse complains.
Upvotes: 1
Views: 8739
Reputation: 1
Try looking in Window >> Preference >> Validation
and disabling the JavaScript Validation
option. See this image.
Upvotes: -1
Reputation: 673
Eclipse is complaining because it is not really Javascript, and it is trying to parse it like Javascript. If it is really annoying you could disable the warning in the preferences, under your own risk to not be notified in other circumstances:
Upvotes: 2
Reputation: 106077
var isFoo = ${actionBean.isFoo};
This is not valid JavaScript, which is why you're getting a syntax error. I'm assuming the ${...}
is supposed to do some interpolation in NetBeans, but Eclipse has no way of knowing that, and just tries to parse it as JavaScript. Unless there's an Eclipse plugin or setting for dealing with mixed code like this, you may just have to deal with seeing syntax errors.
Upvotes: 4