Declarative business rules amount to applying annotations on the appropriate methods. But you should note that Naked Objects does not (currently) support annotations on fields, so it's necessary to put the annotation on the getter for the property.
For example, to indicate that a property is disabled (read-only), we can write:
class Claim ... { String status ... @Disabled String getStatus() { status } }
Other annotations are used as hints for the user interface. For
example the @MemberOrder
is used to specify the
order in which properties and collections appear in the
UI:
class Claim ... { String status ... @MemberOrder("3") String getStatus() { status } }
Another annotation is @Named
, which
commonly appears on action parameters if using built-in value types. For
example, the Claim
's
addItem()
action looks like:
class Claim ... { void addItem( @Named("Days since") int days, @Named("Amount") double amount, @Named("Description") String description) { ClaimItem claimItem = newTransientInstance(ClaimItem.class) Date date = new Date() date = date.add(0, 0, days) claimItem.dateIncurred = date claimItem.description = description claimItem.amount = new Money(amount, "USD") persist(claimItem) addToItems(claimItem) } ... }
The full list of annotations can be found in the Naked Objects applib, and are of course documented in the Naked Objects documentation.