在JSF中将inputText映射到Date对象 [英] Mapping inputText to Date object in JSF

查看:332
本文介绍了在JSF中将inputText映射到Date对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JSF的新手。我试图使用自定义日期选择器(使用jquery和不能用户日历组件)在JSF inpuText组件中获取日期。我想将此inputText映射到bean中的Java Date对象(最终将在Date中存储为Date)。实现此目的的一种方法是将String保留在bean中并在getter和setter中编写转换器,这对我来说并不好看。有没有推荐的方法来解决这个问题。任何帮助/提示/链接表示赞赏。

I am very new to JSF. I am trying to get a Date in JSF inpuText component using a custom datepicker( made using jquery and cannot user calendar component). I want to map this inputText to a Java Date object in the bean (which will eventually stored as Date in DB). One way to achieve this is to keep String in bean and write converters in getters and setters, which doesn't look nice to me. Is there any recommended approach to solve this problem. Any help/hints/links are appreciated.

推荐答案

你可以这样试试

<h:inputText value="#{backingBean.someDate}">  
   <f:convertDateTime pattern="yyyy-MM-dd"/>  
</h:inputText>

其中 someDate 是一个实用日期&在backing bean中有访问器方法。

where someDate is a util date & have accessor methods in the backing bean.

这篇关于在JSF中将inputText映射到Date对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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