Convert JSF calendar date into JodaTime in Converter

放肆的年华 提交于 2019-12-10 06:51:10

问题


JodaTime is amicably the best date and time library out there, maybe.

So I am tempted to receive user input from the front end xhtml Calendar widget in JodaTime instance at the backing bean. Therefore I am thinking of using JSF Converter for this job.

Is this wise to do?

At the same time, since I'm using Primefaces component library and I am already receiving a Date object at my backing bean, would providing a custom Converter require me to do this all over again? I.e. convert from String format to Date object, then to JodaTime DateTime object. Can I somehow let the default JSF convert it to Date first?


回答1:


Just stick to java.util.Date in the model, view and persistence layer (as all have already builtin support for it and you generally don't need to perform date calculations/manipulations at those layers at all) and use JodaTime in business layer only whenever you need to perform calculations/manipulations based on the java.util.Date value. This will keep a lot of things simple.

Once you're on Java 8, migrate java.util.Date to java.time.Local/ZonedDateTime. JSF 2.3 will ship with additional Java 8 support in <f:convertDateTime>. Until then, you'll need to homebrew them as instructed in this answer: How to use java.time.ZonedDateTime / LocalDateTime in p:calendar.



来源:https://stackoverflow.com/questions/11641001/convert-jsf-calendar-date-into-jodatime-in-converter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!