资源束中的值作为formatDate中的模式 [英] value from resource bundle as pattern in formatDate

查看:45
本文介绍了资源束中的值作为formatDate中的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也想从资源包中读取JST 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 ?

是此键:

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

在页面中,我有:

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

这样,${bundle}可以在页面中访问包.您可以通过fmt:message获取消息,并且可以使用其var属性将其存储在本地范围内.然后可以在fmt:formatDate

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

这篇关于资源束中的值作为formatDate中的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆