JSTL <c:set> tag with <fmt> tag

Hi. I don't know much about JSTL, but someone with some knowledge was trying to help me out. Basically I'm trying to set a variable in JSTL with value equal to something referenced by a <fmt> tag. Then I try to get the value of this variable in a scriptlet through the pageContext. The code below doesn't work, however. All I'm getting is an empty string in the scriptlet. Any help would be appreciated.

      <c:set var="selectedValuePresented" value="<fmt:message key='<%= ResourceKeys.DF_SELECT %>'/>" />

      String selectedValuePresented = String.valueOf (pageContext.getAttribute("selectedValuePresented"));
Who is Participating?
You can't nest custom tags as attributes to other custom tags.
However, the c:set takes its value either from the "value" attribute, or the nested content.
You can probably do it like this:
 <c:set var="selectedValuePresented"><fmt:message key='<%= ResourceKeys.DF_SELECT %>'/></c:set>
I am presuming you have a JSP2.0 container (eg Tomcat 5), or are using the "runtime" version of JSTL.

I would question your need for scriptlet code though.  The whole point of JSTL is to minimize it in pages.

I think that <fmt> can also be used to set variable. Please do like
<fmt:message key='<%= ResourceKeys.DF_SELECT %>' var="selectedValuePresented" />

Please try that out

willi_gamboaAuthor Commented:
Thank you. Both approaches work. Regarding minimizing scriptlet code, I completely agree. However, I'm a front end developer whose focus is on DHTML. So any quick way to get the Java developers' code to work with my front end stuff will work for me.

Glad I could help

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.