JSF 2.0 + Primefaces 2.x:将字符串绑定到日历 [英] JSF 2.0 + Primefaces 2.x: Bind string to calendar

查看:96
本文介绍了JSF 2.0 + Primefaces 2.x:将字符串绑定到日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含类型为java.lang.String的字段的bean.该字段包含自由格式的文本,可以表示数字,字符串或日期.当该字段表示日期时,我将在屏幕上呈现一个日历(底图),否则将呈现一个输入框.

I have a bean which contains a field of type java.lang.String. This field holds free-form text which can represent a number, string, or date. When the field represents a date, I render a calendar (primefaces) on the screen, otherwise an input box is rendered.

我遇到的问题是,在用户通过日历选择日期之后,我希望写入我的自由格式字段的日期字符串具有特定格式(MM/dd/yyyy).当前,要设置的字符串具有在java.util.Date对象上执行toString()时所获得的默认格式.

The problem I'm having is that after the user selects the date via the calendar, I would like the date string that gets written to my free-form field to have a specific format (MM/dd/yyyy). Currently the string that gets set has the default format you get when you do a toString() on a java.util.Date object.

有人知道我如何控制写入字段的字符串的格式吗?

Does anyone know how I can control the format of the string that gets written to my field?

谢谢.

推荐答案

我认为应该执行以下操作:

I think the following should do it:

<p:calendar value="#{calTestBean.dateStr}" pattern="MM/dd/yyyy">
    <f:convertDateTime pattern="MM/dd/yyyy"/>
</p:calendar>

这篇关于JSF 2.0 + Primefaces 2.x:将字符串绑定到日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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