JSF 2默认DateTime转换器模式 [英] JSF 2 Default DateTime Converter Pattern

查看:145
本文介绍了JSF 2默认DateTime转换器模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSF页面以以下格式显示托管bean的DateTime:"MM/dd/yyyy h:mm a"

My JSF pages display DateTime from managed beans in this format: "MM/dd/yyyy h:mm a"

我想避免在不同的页面中出现重复的转换器声明:<f:convertDateTime type="both" pattern="MM/dd/yyyy h:mm a" dateStyle="short" timeStyle="medium" />

I want avoid duplicate converter declaration in different pages: <f:convertDateTime type="both" pattern="MM/dd/yyyy h:mm a" dateStyle="short" timeStyle="medium" />

是否可以将上述转换器默认为所有DateTime字段?

Is there a way to make the above converter default for all DateTime fields?

(JSF体验2:2个月.)

(Experience with JSF 2: 2 months.)

推荐答案

只需扩展<f:convertDateTime>后面的rel ="noreferrer"> DateTimeConverter 类,并在构造函数中设置默认值.

Just extend the DateTimeConverter class behind <f:convertDateTime> and set the defaults in the constructor.

@FacesConverter("defaultDateConverter")
public class DefaultDateConverter extends DateTimeConverter {

    public DefaultDateConverter() {
        setPattern("MM/dd/yyyy h:mm a");
    }

}

用作<f:converter converterId="defaultDateConverter" />

请注意,我省略了其他属性,因为在指定pattern时,它们还是会被忽略.

Please note that I omitted other attributes as they are ignored anyway when pattern is specified.

这篇关于JSF 2默认DateTime转换器模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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