*
The moose likes IDEs, Version Control and other tools and the fly likes EL and quotes (HFSJ pg373) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "EL and quotes (HFSJ pg373)" Watch "EL and quotes (HFSJ pg373)" New topic
Author

EL and quotes (HFSJ pg373)

Paul Kemp
Ranch Hand

Joined: Dec 03, 2008
Posts: 35
I'm just reading about EL for the first time.

On page 373 of HFSJ there is an example of servlet code:

String[] favoriteMusic = {“Zero 7”, “Tahiti 80”, “BT”, “Frou Frou”};
request.setAttribute(“musicList”, favoriteMusic);

which can be accessed in a jsp by

${musicList[0]}
${musicList[“1”]}

If I put

${musicList[“1”]}

into the jsp, Eclipse 3.4 gives me an error message "Multiple annotations at this line". If I put

${musicList[1]}

it works fine, and outputs Tahiti 80 to the jsp. I can't use double or single quotes. What am I doing wrong?
Paul Kemp
Ranch Hand

Joined: Dec 03, 2008
Posts: 35
It may be just an Eclipse thing.

If I put

in the servlet

java.util.Map musicMap = new java.util.HashMap();
musicMap.put("Ambient", "Zero 7");
musicMap.put("Surf", "Tahiti 80");
musicMap.put("DJ", "BT");
musicMap.put("Indie", "Travis");
request.setAttribute("musicMap", musicMap);

and in the jsp

Ambient is: ${musicMap["Ambient"]}
Ambient is: ${musicMap[Ambient]}

the top one shows an error in the jsp, and the bottom one doesn't; but when I run it, the top one outputs "Zero 7" correctly and the bottom one outputs nothing, which is the correct behaviour as I understand it.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
paul

the top one shows an error in the jsp, and the bottom one doesn't; but when I run it, the top one outputs "Zero 7" correctly and the bottom one outputs nothing, which is the correct behaviour as I understand it.


second time you run this code with which tool??


Thanks <br />Poonam Agarwal SCWCD 86%
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
the top one outputs "Zero 7" correctly and the bottom one outputs nothing, which is the correct behaviour as I understand it.


yes paul you are right.
1. if you put quote around the elemant in the [] it look for the Map key or Bean property. As in the first case Ambient is: ${musicMap["Ambient"]} it did print the value of the Map key "Ambient" that is Zero 7.

2. But if you do not quote the element the EL search for the attribute by this name and if its find one it will replace with its value. in second case Ambient is: ${musicMap[Ambient]} it look for the Ambient attribute but it dosen't find anythin. so it output nothing.

I hope this will help
Paul Kemp
Ranch Hand

Joined: Dec 03, 2008
Posts: 35
I'm running it from within Eclipse Ganymede 3.4 with Tomcat container in all cases. The results appear to be rendering correctly, as per what is said in HFSJ, it's just that Eclipse is giving me error messages (not warnings) in my jsp when I type in the text above. At run time it seems to work though, which is the weird thing.

I guess we're not supposed to use IDEs for SCWCD but I just wondered if anyone else had encountered this behaviour or am I making a basic error?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Ganymede has a defective XML editor. When you reformat xhtml, it frequently drops quotes form the xmlns attributes, and even when it doesn't, if often flags quoted items incorrectly as having unbalanced quotes. You can tell when you've encountered this bug if you add another quote to the offending item and then delete it and the bogus error indication goes away.

I'm fairly sure that the JSP editor shares some of this defective functionality.

In strict XML, it's not legal to use XML reserved characters in contexts that might confuse the parser. Two of the biggest offenders being use of the less-than/greater-than characters and/or double-quotes within attributes. Which is a primary reason why EL allows alternative, XML-friendly notations.

Basic (non-XML) JSP is more forgiving, but like I said, I think the JSP editor is using XML editor code. It's probably a good idea to use XML-friendly notations even in the JSP, however. Builds good habits.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL and quotes (HFSJ pg373)