Annotations
This guide describes the various annotations used by Apache Causeway to provide additional metadata about the domain objects. Most of these are defined by the framework itself, but some are from other libraries. It also identifies a number of annotations that are now deprecated, and indicates their replacement.
The annotations supported by Apache Causeway break out into several categories.
Core annotations
In Apache Causeway every domain object is either a domain entity, a view model or a domain service. And each of these are made up of properties, collections and actions (domain services only have actions).
For each of these domain types and members there are two annotations. One covers the semantics intrinsic to the domain (eg whether an action parameter is optional or not), then other (suffix …Layout
) captures semantics relating to the UI/presentation layer.
Most UI semantics can also be specified using dynamic object layout. |
The table below summarizes these most commonly used annotations in Apache Causeway.
Annotation | Purpose | Layer | File-based layout? |
---|---|---|---|
Domain semantics for actions |
Domain |
||
User interface hints for actions |
UI |
Yes |
|
Domain semantics for collections |
Domain |
||
User interface hints for collections |
UI |
Yes |
|
Domain semantics for domain object (entities and optionally view models) |
Domain |
||
User interface hints for domain object (entities and optionally view models) |
UI |
Yes |
|
Class is a domain service (rather than an entity or view model) |
Domain |
||
User interface hints for domain services |
UI |
||
Domain semantics for action parameters |
Domain |
||
Layout hints for an action parameter (currently: its label position either to top or the left). |
UI |
Yes |
|
Domain semantics for properties |
Domain |
||
Layout hints for a property |
UI |
Yes |
Other Causeway Annotations
There are a number of other annotations defined by the framework, for a variety of purposes.
The following are commonly used:
Annotation | Purpose | Layer |
---|---|---|
Query-only action (on domain service) to be invoked, result of which is rendered as the user’s home page. |
UI |
|
Minimum number of characters required for an auto-complete search argument. |
UI |
|
Indicates which of the object’s properties should be used to build up a title for the object. |
UI |
The following are used to indicate whether a given should be included or excluded in the metamodel. Whether they are required depends on the setting of causeway.core.meta-model.introspector.policy, but it is always safe to use them.
Annotation | Purpose | Layer |
---|---|---|
Explicitly include the method as part of the metamodel. |
UI/Domain |
|
Explicitly exclude the method as part of the metamodel. |
UI/Domain |
|
Intended to be annotated on |
Domain |
|
Intended to be annotated on |
UI |
|
Intended to be annotated on |
Persistence |
|
Indicates that a method is to be called only programmatically, and so is not part of the metamodel. Equivalent to (and the original name of) @Domain.Exclude |
UI/Domain |
The next annotations relate to the overall system architecture.
Annotation | Purpose | Layer |
---|---|---|
An alias for Spring’s own |
Domain |
|
Annotated on a domain service to indicate that it should be scoped by the interaction (roughly equivalent to an HTTP request). |
Domain |
The final annotations relate to the definition of custom value types:
Annotation | Purpose | Layer |
---|---|---|
Marker annotation that indicates the object is a value type (as opposed to a domain service, entity, view model or mixin). Value types also require an implementation of a ValueSemanticsProvider. |
Domain |
|
Annotated on a property or parameter, indicating that the property/parameter’s type should be considered a value type, and supplying details of the service implementing ValueSemanticsProvider that describes how the framework should interact with the value type. |
Domain |
Java EE Annotations
While Apache Causeway does define many of its own annotations, the policy is to reuse standard Java/JEE annotations wherever they exist or are added to the Java platform.
The table below lists the JEE annotations currently recognized.
Annotation | Purpose | Layer |
---|---|---|
Precision/scale for BigDecimal values. |
Domain |
|
Regular expressions for strings |
Domain |
|
Specify that a property/parameter is optional. |
Domain |
JAXB Annotations
Annotation | Purpose | Layer |
---|---|---|
JAXB annotation indicating the XML root element when serialized to XML; also used by the framework for view models (whose memento is the XML), often also acting as a DTO. |
Application |
|
JAXB annotation defining how to serialize an entity. Used in conjunction with the (framework provided) |
Domain |
JPA Annotations
The table below lists the JPA/EclipseLink annotations currently recognized by Apache Causeway.
Annotation | Purpose | Layer | Applies to |
---|---|---|---|
Flags that the class is an entity, creating an abstraction layer through which the Causeway framework interacts with the underlying persistent domain object. |
Domain / persistence |
Class |
Causeway also parses the following JPA annotations, but the metadata is currently unused.
Annotation | Purpose | Layer | Applies to |
---|---|---|---|
|
Unused |
Persistence |
Property |
|
Unused |
Persistence |
Class |
JDO Annotations
The table below lists the JDO/DataNucleus annotations currently recognized by Apache Causeway.
Annotation | Purpose | Layer | Applies to |
---|---|---|---|
Used to determine whether a property is mandatory or optional. For |
Domain / persistence |
Property |
|
Infer the logical type name.
This takes precedence of |
Domain / persistence |
Class |
|
Used to determine whether to enforce or skip some metamodel validation on nullability ( |
Domain / persistence |
Property |
|
The Internally, it also flags that the class is an entity, creating an abstraction layer through which the Causeway framework interacts with the underlying persistent domain object. |
Domain / persistence |
Class |
|
Used to ensure Apache Causeway does not overwrite application-defined primary keys, and to ensure is read-only in the UI. |
Domain / persistence |
Property |
Causeway also parses the following JDO annotations, but the metadata is currently unused.
Annotation | Purpose | Layer | Applies to |
---|---|---|---|
@javax.jdo.annotations. |
Unused |
Persistence |
Class |
@javax.jdo.annotations. |
Unused |
Persistence |
Class |
@javax.jdo.annotations. |
Unused |
Persistence |
Class |
@javax.jdo.annotations. |
Unused |
Persistence |
Class |
Examples
To give just a few examples of annotations supported by Apache Causeway:
-
if a property is read-only, then this can be annotated with
@Property(editing=Editing.DISABLED)
. -
if a class has a small fixed set of instances (eg a picklist), then it can be annotated using
@DomainObject(bounded=true)
-
if a class is a domain service and should be automatically instantiated as a singleton, then it can be annotated using
@DomainService
-
if an action is idempotent, then it can be annotated using
@Action(semantics=SemanticsOf.IDEMPOTENT)
. -
if an action parameter is optional, it can be annotated using
@Parameter(optionality=Optionality.OPTIONAL)
Some annotations act as UI hints, for example:
-
if a collection should be rendered "open" rather than collapsed, it can be annotated using
@CollectionLayout(defaultView="table")
-
if an action has a tooltip, it can be annotated using
@ActionLayout(describedAs=…)
-
if a domain object is bookmarkable, it can be annotated using
@DomainObjectLayout(bookmarking=BookmarkPolicy.AS_ROOT
).