Brenda Nicole Tan
Brenda Nicole Tan

Reputation: 5604

Evaluating a Struts value within a JSTL tag

I'm currently developing a language pack for an application built on Struts 2. The language pack is defined in a properties file which will be accessed by the frontend JSP via JSTL (FMT tags).

I'm trying to achieve something like String formatting, i.e. inserting a Struts value into a sentence string retrieved via an FMT tag.

What's defined in my properties file:

userprofile.link.text = <a href="{0}">Click here</a> to view your profile page.

And from the JSP side,

<fmt:message key="userprofile.link.text">
   <fmt:param value='/profile/<s:property value="userBean.id"/>'/>
</fmt:message>

However, the link does not render correctly. How do I achieve this ?

Upvotes: 1

Views: 614

Answers (1)

Andrea Ligios
Andrea Ligios

Reputation: 50203

  1. JSTL uses ${} (EL);

  2. Struts2 ValueStack is exposed to JSTL through the StrutsRequestWrapper:

    All Struts requests are wrapped with this class, which provides simple JSTL accessibility. This is because JSTL works with request attributes, so this class delegates to the value stack [...]

Then this should be enough:

<fmt:message key="userprofile.link.text">
    <fmt:param value='/profile/${userBean.id}'/>
</fmt:message>

Upvotes: 1

Related Questions