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 five 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 Apache Causeway Annotations
These annotations are also commonly used, but relate not to objects or object members but instead to other aspects of the Apache Causeway metamodel.
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 |
|
Ignore a public method, excluded from the Apache Causeway metamodel. |
Domain |
|
Indicates which of the object’s properties should be used to build up a title for the object. |
UI |
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 |
|
Override for the object type, as used in `Bookmark`s, URLs for RestfulObjects viewer and elsewhere. Note that the discriminator overrides the object type that may otherwise be inferred from the @PersistenceCapable annotation. |
Domain / persistence |
Class |
|
Used to determine whether to enforce or skip some metamodel validation for |
Domain / persistence |
Property |
|
Used to build Apache Causeway' own internal identifier for objects. If the |
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 |
JPA Annotations
TODO: v2 - JPA is now also supported as an ORM. (As with JDO), some of JPA’s annotations are recognised by Apache Causeway.
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. Expect to see more added in future releases of Apache Causeway.
Annotation | Purpose | Layer | File-based layout? |
---|---|---|---|
Precision/scale for BigDecimal values. |
Domain |
||
Regular expressions for strings |
Domain |
||
Specify that a property/parameter is optional. |
Domain |
||
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 |
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=EditingDISABLED)
. -
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
).