问题
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