• Post Reply Bookmark Topic Watch Topic
  • New Topic

EL expression - order of evaluation?

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse the bloated code, this is just a test setup for proof-of-concept thing.

A servlet is creating maps with information about stored procedures and then an array of the names of those maps, like so:


The array is so I can tell how many maps have been created and their names. Here's the puzzle.

This expression evaluates to "sp1" as expected:

And of course this returns the value that I want

So why can't I do this?

That throws a "Property 'desc' not found on type java.lang.String" error which seems to imply that it's looking for the property "desc" before it's evaluated the "splist[0]" part of the expression. Is there a better way to do this?

Let me step back a few feet and explain the design issue. I won't know ahead of time how many maps I'll get from the servlet and I want to populate a select/option dropdown list with the descriptions. I guess I could have the servlet just set a number 'x' instead of sending an array and I can assume the map names are 'sp(x)' and use x as the loop counter, but that seems inflexible. I may need to use a similar technique in another app where I won't know anything about the map names.

There is a similar example in HFSJ that uses the format ${musicmap[MusicType[0]} but that's a little different from my needs. I have the key name and need the map name. The HFSJ example has the map name and gets the key name from an array. This also leads me back to suspect a left to right evaluation issue.

Any thoughts, ideas or "what the hell are you doing" comments are welcome.

 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jk Robbins wrote:This expression evaluates to "sp1" as expected


Yes, it evaluates to that string. But it appears you don't want that string. In other words you want the expression to evaluate to sp1, not to "sp1". So don't use a String array in your code. Use an array of Maps and put references to s1 and s2 in the array.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Jk Robbins wrote:This expression evaluates to "sp1" as expected


Yes, it evaluates to that string. But it appears you don't want that string. In other words you want the expression to evaluate to sp1, not to "sp1". So don't use a String array in your code. Use an array of Maps and put references to s1 and s2 in the array.


Nice. Now it's working. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!