`
even713
  • 浏览: 17590 次
  • 性别: Icon_minigender_2
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

I18N modification(1)

    博客分类:
  • java
阅读更多

There is a bean set in xml, and has a method called getAllShareScopes which return a collection has a map of select element.

I found the getAllShareScopes method is simple, just return allShareScopes.

So where and when dose it get the value?

I found afterPropertiesSet methods, and knew the allShareScopes get value there.

And what's new to me is that, the afterPropertiesSet methods is invoked when the service is started, that is to say, when the server starts, the settings in xml files will be setted, and all the values may be stored in application!

 

The I18N work seems to be done when the server starts:

 

ctx.getMessage(scope.getLabelKey(), null, Locale.getDefault());

 

It's absolutely wrong, because we should get the client locale instead of the server's locale.

So the I18N work shouldn't be done here.

What we can do here is fetch the key value: String label = scope.getLabelKey();

Then do the i18n work in jsp file like:

 <c:forEach var="scope" items="${allShareScopes}">
         <option value="${scope.name}"><fmt:message key="${scope.label}"/></option>
 </c:forEach>

 

This may be simple to others, but I learnt some from the research and fixing, so I record it.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics