Joda Time
This module provides support for four of the Joda Time value types.
In most cases it is recommended to instead use the similar JDK classes (in the java.time
) packages.
However, Joda is well-established, and you may prefer it, or have legacy applications not yet converted to use the JDK classes.
These are the Joda Time classes supported:
Joda Time class | JDK equivalent |
---|---|
|
|
|
|
|
|
|
|
The module’s support consists of:
-
implementations of ValueSemanticsProvider for these types so that the framework can interact and render these values types appropriately (eg with date/time pickers)
-
implementations of
javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
(nested subsclasses ofo.a.c.valuetypes.jodatime.applib.jaxb.JodaTimeJaxbAdapters
) to allow these values to be used in JAXB view models.
Note that both the persistence mechanisms have their own support for persisting these Joda-time types; consult their respective documentation:
-
JPA/Eclipselink has the
@Convert
and@Converter
annotations.See JPA docs for more details.
-
JDO/DataNucleus requires the
org.datanucleus:datanucleus-jodatime
Maven dependency.See JDO docs for more details.
Setup
Dependency Management
In your application’s top level pom.xml
, add a dependency for this module’s own bill of materials (BOM):
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.causeway.valuetypes</groupId>
<artifactId>causeway-valuetypes-jodatime</artifactId>
<scope>import</scope>
<type>pom</type>
<version>3.1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Dependencies / Imports
In those modules where there are domain objects that use the Joda Time value types within JAXB view models:
-
add this dependency:
pom.xml<dependencies> <dependency> <groupId>org.apache.causeway.valuetypes</groupId> <artifactId>causeway-valuetypes-jodatime-applib</artifactId> </dependency> </dependencies>
-
and
@Import
this module:MyModule.java@Configuration @Import({ CausewayModuleValJodatimeApplib.class, // ... }) public class MyModule { ... }
In addition, in the webapp module of your application, add the following dependencies:
-
for the metamodel:
pom.xml<dependency> <groupId>org.apache.causeway.valuetypes</groupId> <artifactId>causeway-valuetypes-vega-ui-wkt</artifactId> </dependency>
And in your application’s App Manifest, import the extension’s implementation module:
@Configuration
@Import({
CausewayModuleValJodatimeIntegration.class,
...
})
public class AppManifest {
}
Usage
The property can be declared and used in both entities and view models.
-
if declared in an JPA entity, see the JPA docs for more details.
-
if declared in an JDO entity, see the JDO docs for more details.
-
if declared in a JAXB view model, annotate with the appropriate
XmlJavaTypeAdapter
:@Property @PropertyLayout @XmlElement(required = true) @XmlJavaTypeAdapter(JodaTimeJaxbAdapters.LocalDateToStringAdapter.class) @Getter private LocalDate createdOn;