Package org.omnifaces.cdi.config
Class DateProducer
- java.lang.Object
-
- org.omnifaces.cdi.config.DateProducer
-
public class DateProducer extends Object
Producer for
#{startup}
and#{now}
.Since 4.0 it produces by default an instance of
Temporal
whereas it previously produced an instance ofDate
.Historical note: since 1.0 these were registered as beans in faces-config.xml. Since 3.6 these were migrated to CDI producers, because the CDI implementation being used may emit warnings on them not being proxyable.
Usage
- You can reference the application startup time as
Temporal
via#{startup}
in EL. - You can reference the current time as
Temporal
via#{now}
in EL. - They have a
DateProducer.TemporalDate.getTime()
method which allows you to obtain the epoch time via#{startup.time}
and#{now.time}
in EL. - They have a
DateProducer.TemporalDate.getInstant()
method which allows you to convert them toInstant
atZoneOffset.UTC
via#{startup.instant}
and#{now.instant}
in EL. - They have a
DateProducer.TemporalDate.getZonedDateTime()
method which allows you to convert them toZonedDateTime
atZoneId.systemDefault()
via#{startup.zonedDateTime}
and#{now.zonedDateTime}
in EL. - They are injectable in CDI beans via e.g.
@Inject @Named private Temporal startup;
.
- Since:
- 3.6
- Author:
- Bauke Scholtz
- You can reference the application startup time as
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DateProducer.TemporalDate
ZonedDateTime
is a final class, hence this proxy for CDI.
-
Constructor Summary
Constructors Constructor Description DateProducer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DateProducer.TemporalDate
getNow()
This makes an instance ofTemporal
as current datetime available by#{now}
.DateProducer.TemporalDate
getStartup()
This makes an instance ofTemporal
as startup datetime available by#{startup}
.
-
-
-
Method Detail
-
getStartup
@Produces @Named @ApplicationScoped @Eager public DateProducer.TemporalDate getStartup()
This makes an instance ofTemporal
as startup datetime available by#{startup}
.- Returns:
- Startup datetime.
-
getNow
@Produces @Named @RequestScoped public DateProducer.TemporalDate getNow()
This makes an instance ofTemporal
as current datetime available by#{now}
.- Returns:
- Current datetime.
-
-