• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another EL question

 
Yusuf Hussain
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I was wondering about chapter 8 question #1 in HFSJ. It states that both of the following EL expessions and improper syntax.

${paramValues[hobbies][0]}
${paramValues[hobbies][1]}

I was thinking that the syntax is incorrect because there are no quotes around hobbies. Would this be valid?

${paramValues["hobbies"][0]} Wouldn't paramValues["hobbies"] resolve to a list object?

Thanks very much.
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with ${paramValues[hobbies][0]} is indeed the quotes are missing (either single or double).

A corrected version of : ${paramValues["hobbies"][0]} would correctly retrieve the first value of the hobbies parameter.

The second one ( ${paramValues[hobbies][1]} ) is wrong because :
- same problem, quote are missing;
- 1 is index of the second value, and we want first value (indices start at 0).

To answer your last question, paramValues is a Map mapping a key (parameter name) to a String array of values.
In generic notation, paramValues is :

Map<String, String[]> paramValues;

So, paramValues["hobbies"] resolves to a String[] containing values of the parameter named hobbies.

Hope this helps.
[ March 07, 2006: Message edited by: Frederic Esnault ]
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't know the Question context, but how

${paramValues[hobbies][0]} is invalid if there is a scoped variable hobbies is available which return String. Is the quote is nessessary.

Thanks
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is right, if a hobbies variable is available holding a String which is actually the name of a parameter, then the quotes are not necessary.

Still, the result is unsure because you cannot be sure that hobbies variable is not guaranteed to hold the String "hobbies" and then may hold another parameter name

But basically, you're right, without quotes, it's evaluated and so it may work. But if it's not said in the context, do not suppose it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic