aspose file tools*
The moose likes JSP and the fly likes Processing dynamic variable in JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Processing dynamic variable in JSTL" Watch "Processing dynamic variable in JSTL" New topic
Author

Processing dynamic variable in JSTL

mahesh rao
Greenhorn

Joined: Sep 08, 2004
Posts: 19
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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]}


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
mahesh rao
Greenhorn

Joined: Sep 08, 2004
Posts: 19
Thanks, that worked.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Originally posted by mahesh rao:
Thanks, that worked.


That's cool! But do you understand why that works?
mahesh rao
Greenhorn

Joined: Sep 08, 2004
Posts: 19
Yes (pageScope is default scope). Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Processing dynamic variable in JSTL