1

I am still new a Javascript tried earching and tried the development tool in Chrome, too see if I could find the problem.

Working in Intellij IDEA 13, Java, javascript and xhtml.

My problem is that I have a piece of javascript, then in IDEA when moused over, says that

Expression Expected

the javascript code looks the following

<script type="text/javascript>    
    function nameOfFunction(){
        if(#{trendAnalysisLocationReportController.model.showTargetLine}){
             this.cfg.series[this.cfg.data.length-1].pointLabels = {
                show: false
             };
        }
    }
<\script>  

the method in the if sentence is a java method with a boolean return value. the error is shown when hovering

'#{'

if Had a look at the following questions, before : Expected Expression boolean in an if statement

But didnt get me a solution. what Iam I doing wrong ?

Community
  • 1
  • 1
Jesper
  • 119
  • 1
  • 3
  • 15
  • 1
    why are you trying to mix java and javascript? showTargetLine doesn't strike me as a methodname that returns a boolean, btw – Stultuske Aug 17 '15 at 08:01
  • 1
    `#` is not a proper JavaScript code, thus the if condition can't be executed. – cezar Aug 17 '15 at 08:01
  • Also if you need a boolean you have to make some comparison or call a method that returns a boolean value. The curly braces are used in JavaScript for object literal notation. In your if-condition they aren't properly used. Assuming that `showTargetLine` is a method, the concerned line should be `if ( trendAnalysisLocationReportController.model.showTargetLIne() ) { // condition body }`. – cezar Aug 17 '15 at 08:04

1 Answers1

1

It looks as though the problem is the part that you've got within the #{...} block. Without knowing the context, it's hard to be sure, but is this something in a view/JSP page that's supposed to be replaced with a property at runtime? The if block will expect the part inside the brackets to be a boolean value, so if that's rendered to either 'true' or 'false' it would execute at runtime but would likely show the error you're seeing in your IDE as it's not actually a valid piece of JavaScript. If, on the other hand, you're expecting to be able to call your Java method/property from your JavaScript code, you're going to need to do something that requests that value from the server-side code - AJAX or similar.

Also worth noting that we can't see what this.cfg is supposed to represent. If that's your entire script block, then there's nothing that defines the cfg object within the current scope.

One last thing, you should change the <\script> end element to as it won't be understood properly by some browsers.

Chris Disley
  • 1,286
  • 17
  • 30
  • You are spot on there, I want it to be replaces with a property at runtime. So its an error msg, that is shown in IDEA because it cant show what this will be runtime ? – Jesper Aug 17 '15 at 08:27
  • 2
    Believe so, yes. Best bet is compile, run and check it to be sure, but seems that way. I'm not a big IDEA user, but I've done similar in ASP.NET and Visual Studio and seen the same sort of thing. Works fine, but IDE throws up warnings or errors because it's not made to evaluate the dynamic part of the page before checking the JS. – Chris Disley Aug 17 '15 at 08:41