Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSF calendar date into JodaTime in Converter

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?

like image 260
Oh Chin Boon Avatar asked Dec 20 '22 18:12

Oh Chin Boon


1 Answers

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.

like image 190
BalusC Avatar answered Dec 28 '22 06:12

BalusC