开发者

value from resource bundle as pattern in formatDate

I want to read pattern for JST formatDate also from resource bundle but this naive approach does not working, what I'm doing wrong ?

in com/company/MyPortlet.properties is this key:

company.date.format = yyyy-MM-dd HH:mm:ss

In page I have:

<fmt:setBundle basename="com.company.MyPortlet"/>
<fmt:formatDate value="${date}"  pattern="${company.date.format}" />开发者_开发问答


You need to give the bundle a variable name.

<fmt:setBundle basename="com.company.MyPortlet" var="bundle" />

This way bundle is accessible in the page by ${bundle}. You can get messages by fmt:message and you can use its var attribute to store it in a local scope. Then you can use it in the pattern attribute of the fmt:formatDate

<fmt:message bundle="${bundle}" key="company.date.format" var="pattern" />
<fmt:formatDate value="${date}" pattern="${pattern}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜