Actions - miguelperezcolom/mateu GitHub Wiki

Once the user sees the UI he/she can trigger any logic by initiating an Action. An action is visible for the user as a Button in the UI.

With Mateu you declare an action by annotating a method with the @Action or @MainAction annotation (or a field of type Callable or Runnable with the or @Button annotation). That paints a button in the UI and, when the user clicks that button, in the server side an object is created and populated and the method is called.

According to the annotation you are using the button will be painted on the top area of the form or in the bottom. Fields annotated with @Button are painted at the position of the field. E.g. the following code:

@Service
@Caption("Actions as buttons")
public class ActionsAsButtonsForm {

    String name = "Mateu";

    @Button(target = ActionTarget.NewModal)
    @SameLine
    @FlexGrow("0")
    Callable<ChangeNameForm> changeName = () -> new ChangeNameForm(name, this);

    @Button(type = ActionType.Secondary)
    Runnable setRandomName = () -> name = UUID.randomUUID().toString();

    @Action
    void thisIsAnAction() {

    }

    @MainAction(type = ActionType.Tertiary, position = ActionPosition.Left)
    void yetAnotherMainAction() {

    }

    @MainAction(type = ActionType.Secondary)
    void anotherMainAction() {

    }

    @MainAction
    void aMainAction() {

    }

}

Will be painted as:

There are several parameters that you can use for the @Action, @MainAction and @Button annotations:

Parameter Description Comments
value Button text If not present it will be inferred from the method/field name
icon Icon
confirmationTitle Title for the confirmation dialog
confirmationMessage Message for teh confirmation dialog
confirmationAction Text for the confirmation button
validateBefore If the form must be valid befor running this action
rowsSelectedRequired When used in Cruds, if some rows must be selected for running this action
order Position in the list of actions Reflection does not warranty the order for methods
type Can be Primary, Secondary or Tertiary
target Where to place the result of this method
targetId E.g. the component id
modalStyle Css to be applied to the modal window E.g. the width and height
customEvent Name of the event in case the result of this action is throwing an event This will become a CustomEvent in the frontend
href In case the result of this action is to go to another url in the browser E.g. another menu option
runOnEnter If we want this action to be called when the user presses Enter
position Used for @MainAction. Can be Left or Right
timeoutMillis If we want this action to be automatically called after a timeout
closeModalWindow If after calling this action the modal window must be closed

Method parameters

Please notice that if your method contains parameters (which Mateu can not inject) a form will be presented to the user for gathering those values, before the method is actually called.

⚠️ **GitHub.com Fallback** ⚠️