1

I have a navigation bar in a .jsp file whereby I want it where if an imported java condition returns null then (using inline css), set the link in the navigation to display:none; else display:block; This is what I came up with so far but eclipse doesn't seem to like it when I add none and block:

<li><a style="display:<%if(Settings.getInstance().getExternalDataLocation()!= null){
        none;" 
        }else{
        block;"}%> 
</li>

The following errors also seem to appear under the red lines of 'none' and 'block':

- Syntax error, insert "VariableDeclarators" to complete 
 LocalVariableDeclaration
- Syntax error on token "block", } expected
- Syntax error, insert ";" to complete BlockStatements

I'm sure the errors are self explanatory but I still cant seem to get my head round resolving them or even knowing if I am missing the correct syntax. Hope someone can point me in the right direction.

Zoe
  • 181
  • 1
  • 2
  • 11
  • 1
    I guess you have a misplaced `"`. Try this: style="display:'<%if(Settings.getInstance().getExternalDataLocation()!= null){ none; }else{ block;}%'"> – user63762453 Jul 14 '14 at 10:39
  • I guess you have a misplaced ". Try this: style="display:<%if(Settings.getInstance().getExternalDataLocation()!= null){ none; }else{ block;}%"> – user63762453 Jul 14 '14 at 10:57

1 Answers1

2

Try this instead,

   <li>
        <%if(Settings.getInstance().getExternalDataLocation()!= null){%>
        <a style="display:none;">
        <%}else{%>
        <a style="display:block;">
        <%}%>        
    </li>

But however using scriptlets are considered to be bad since a decade . try to use jstl or el

see this post for more info How to avoid Java code in JSP files?

Hope this helps!!

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • Thank you everyone for the quick responses. I have tried your solution san and it has worked successfully and is far more comprehensible then my initial idea. I did not realise how much scriptlets are discouraged and deliver such limitations. I probably will look more into the alternatives you have mentioned to avoid hindering my project as a whole. Thanks again. – Zoe Jul 14 '14 at 12:13