value from resource bundle as pattern in formatDate

随声附和 提交于 2021-02-04 19:00:31

问题


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}" />

回答1:


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}" />


来源:https://stackoverflow.com/questions/2883233/value-from-resource-bundle-as-pattern-in-formatdate

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