Evaluating a Struts value within a JSTL tag

↘锁芯ラ 提交于 2019-12-23 02:57:13

问题


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 ?


回答1:


  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>


来源:https://stackoverflow.com/questions/34263798/evaluating-a-struts-value-within-a-jstl-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!