@Action
The @Action annotation simplifies writing actions. The annotation
is added to a method and that method is wrapped in a transaction. The transaction can be
read-write or read-only depending on whether the @Action.mutation parameter
is true or false. By default actions use read-write transactions.
The annotation also defines parameters that control the name of the action and whether the methods parameters
are logged during development mode. See the @Action API documentation for further details.
Use @Action.skipIfDisposed to skip an action when the owning component
is disposing or disposed; the action must be void and the skip emits a spy event. The parameter is of type
Feature. If it is left as AUTODETECT then it inherits from
@ArezComponent.defaultSkipIfDisposed, and if the
component default is also AUTODETECT then the effective behavior is DISABLE.
Actions are usually invoked in response to an event in the system, whether that been in response to a user action or a network response.
An example:
@ArezComponent
public abstract class Wallet
{
@CascadeDispose
@Nonnull
final Currency aud = new Arez_Currency();
// A read-write action that updates observable value
@Action
public void updateAustralianDollarBalance( final BigDecimal newBalance )
{
aud.setAmount( newBalance );
}
// A read-only action that queries observable value
@Action( mutation = false )
public boolean holdsAnyAustralianDollars()
{
return aud.getAmount().compareTo( BigDecimal.ZERO ) > 0;
}
}