是否可以为整个struts webapp配置日期格式的统一格式? [英] Is it possible to configure unified format of date format for whole struts webapp?

查看:87
本文介绍了是否可以为整个struts webapp配置日期格式的统一格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何情况下,id都会获得异常Could not parse date.

In any case id get exception Could not parse date.

有统一的日期格式公司标准-'dd/MM/yyyy'

There is unified company standard of date format - 'dd/MM/yyyy'

有些计算机具有不同的系统区域设置.我在datepicker上使用jQueryUI(这是小部件的标准配置,并且已经确定了CSS样式以匹配应用程序主题).

There are computers with different system locales. I am using jQueryUI for datepicker ( it is standard for widgets and already settled css styles to match application theme).

开始时,我没有找到更好的解决方案,然后使用SimpleDateFormat对象将日期字符串手动转换为date对象.现在,我具有转换器类,但仍需要配置具有java.util.Date属性的每个Action.

At the beginning, i didn't found better solution then manually convert date string to date object using SimpleDateFormat object. Now i have converter class but still need to configure every Action that has java.util.Date property.

我正在使用XML配置,并且确实尝试添加到struts.xml:

I am using XML configuration and I did try to add into struts.xml:

<constant name="struts.date.format" value="dd/MM/yyyy" />

那没有用.

有没有什么可以迫使所有Web应用程序使用单一日期格式而没有区域设置,而只是统一格式的输出和输入日期呢?

Is there anything that can force all web-application to use single date format without locales just a unified format for output and input date?

或者是我如何提取struts日期类型转换器期望的日期格式的方式,以便我可以使用js在将日期发送到服务器之前转换日期以匹配struts期望?

Or the way how i can extract date format expected by struts date type converter, so i can use js to convert date before to be sent to server to match struts expectations?

推荐答案

Struts2旨在根据客户端请求的语言环境来表现不同.

Struts2 is designed to behave differently according to a locale requested by the client.

i18n拦截器是默认拦截器的成员堆.因此,它负责将请求的语言环境设置为操作上下文,从而覆盖默认设置.如果请求参数未请求该语言环境,它还将该语言环境存储到会话中以进一步检索该语言环境.

i18n interceptor is a member of the default interceptor stack. So, it is responsible for setting requested locale to the action context, overriding the default settings. It also stores that locale to the session for further retrieving it if the locale is not requested by the request parameter.

默认类型转换器使用操作上下文的语言环境,因此将语言环境设置为操作上下文可能会覆盖可以通过struts.locale配置的默认语言环境设置,而i18n拦截器不会对此进行更改.

The action context's locale is used by the default type converter, so setting a locale to the action context should probably override the default locale setting which could be configured via struts.locale and i18n interceptor doesn't change this.

如果是这样,则无需执行其他任何操作,只需根据该语言环境将日期格式放入全局资源属性即可.由于i18n请求的区域设置一起使用的具有不同格式的动作属性. rel ="nofollow noreferrer">处理本地化资源的顺序.

If so, no other actions required, just put your date format to the global resource properties according to that locale. You can also use action properties that could be used with i18n requested locale that has different format due to the order of processing localization resources.

如果您不需要用户切换语言环境的可能性,则应从堆栈中删除i18n拦截器.

If you don't need that possibility of switching a locale by the user you should remove i18n interceptor from the stack.

如何使用操作上下文的语言环境设置日期和数字的格式:格式化日期和数字.

How to format the dates and numbers using action context's locale: Formatting Dates and Numbers.

这篇关于是否可以为整个struts webapp配置日期格式的统一格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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