This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL concatenation -> ${map[ ?+? ]} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL concatenation -> ${map[ ?+? ]}" Watch "EL concatenation -> ${map[ ?+? ]}" New topic

EL concatenation -> ${map[ ?+? ]}

Dimiter Stoinov

Joined: Jul 06, 2004
Posts: 3
Hi guys,

Have the following snippet:

<jsp:useBean id="map" class="java.util.HashMap"/>
map.put("a123", "object");
pageContext.setAttribute( "id", "123" );
${map[ 'a' + id ]}

Trying to concat 'a' with some existing attribute to get the map value. No success so far. How can i concat values inside the [] brackets?

Can you give me a hint please.

Thank's for your time
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Im not sure about it but did u try it with String rather than char?
You can try ["a"+123].


Dimiter Stoinov

Joined: Jul 06, 2004
Posts: 3
Problem is that + is used for addition so "a"+"somethingelse" else gives plenty nice errors of type:
javax.servlet.ServletException: An exception occured trying to convert String "a1" to type "java.lang.Long" / or "java.lang.Double"

Following code is solution, but i rather wanted the concatenation inside the [ ] brackets

<jsp:useBean id="map" class="java.util.HashMap"/>
map.put( "a123", "object");

final String s = "a" + "123";
pageContext.setAttribute( "id", s );

${map[ id ]}

[ July 07, 2004: Message edited by: Dimiter Stoinov ]
It is sorta covered in the JavaRanch Style Guide.
subject: EL concatenation -> ${map[ ?+? ]}
Similar Threads
concat() function
*Stateless* methods vs. functions
EL concatenation -> ${map[ ?+? ]}
Issues in JAXB conversion of List<String>
How get haspmap in inserted order?