Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure about it but did u try it with String rather than char?
You can try ["a"+123].

Regards,
Leena
 
Dimiter Stoinov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Hey! You're stepping on my hand! Help me tiny ad!
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic