• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Processing dynamic variable in JSTL

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have problem getting the result of a JSTL variable dynamically. Here is the scenario.
I have defined messages for some status values as follows in the page.

<c:set var="messagestatus1a" value="Less than 30 days with ME" /> <c:set var="messagestatus1b" value="30 days or more with ME" /> <c:set var="messagestatus2a" value="Less than 30 days with JPM"/> <c:set var="messagestatus2b" value="30 days or more with JPM" />

I get a status value from the database (such as status1a, status1b, status2a, status2b) and I am concatenating with 'message' so that I can frame the appropriate variable name.

<c:forEach var="suggestionsLoop" items="${suggestionQuery.rows}">
<c:set var="msgDesc" value="message${suggestionsLoop.status}" />
<!-- Now, 'msgDesc' variable has a value like 'messagestatus1a' or 'messagestatus1b' etc.,
I would like to reprocess the value from msgDesc to diaplay the appropriate message.
If I try ${${msgDesc}} obviously I am getting error. Any ideas how to accomplish this ?
-->
</c:forEach>

Thanks,
vmrao
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mahesh rao:
I have defined messages for some status values as follows in the page.



Rather than hard-coding these on the page, you might want to consider putting them in a Map established in app scope at startup.

${${msgDesc}} obviously I am getting error



Do you have a copy of the JSP Spec which has a section on the syntax of the EL? If not, you should!

Try ${pageScope[msgDesc]}
 
mahesh rao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that worked.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mahesh rao:
Thanks, that worked.



That's cool! But do you understand why that works?
 
mahesh rao
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes (pageScope is default scope). Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic