SpringBoot (14) Let's start (3/10). Defining an action form from scratch.

 0. Introduction

In a previous post, we could see how to define an action form in the YAML file src/main/resources/config/menus/menus.yml

Let's define an action form that counts from one number to another and displays the counting process to the form.

These steps should be followed:

  1. Define the menu item in the YAML file and also update the field idFills from the parent menu item
  2. As no special form is needed the field url should be assigned "/generalActionForm"
  3. Create a Java class in the package ximo.actions with a execute method that accepts two arguments (numbers from and to) and displays the count from the number from to the number to.


1. Updating the menus.yml file

Here is the menus.yml file. Notice the yellow elements.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
menus:
  items:
  #--- Negociats: Nivell 0
    - { id: 8, name: Informatica,    idFills: [8-1, 8-2, 8-3] }
    - { id: 8-3, name: DantesqueSpringBootExample, specialRole: ADMIN, url: /generalActionForm,
        processClassName: X01_DantesqueSpringBootExample,
        title: X01_DantesqueSpringBootExample,
        subtitle: Counting from one paramenter to another,
        lFields: [ 
          { name: numberFrom, label: Number from,  component: NUMBER,  value: 0  },
          { name: numberTo,   label: Number to,    component: NUMBER,  value: 10 },
        ]    
      }


2. Creating the java class with the execute method to be executed

Here is the java class in the ximo.actions package


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package ximo.actions;

import ximo.config.actions.ActionBaseEdu;

public class X01_DantesqueSpringBootExample extends ActionBaseEdu{
  @Override
  public void execute() {
    System.out.println("A22_DantesqueSpringBootExample.execute ....");
    this.showMessage("Initilizing .....");
    this.showSeparator();
    	
    int numberFrom=Integer.parseInt((String) this.map.get("numberFrom"));
    int numberTo  =Integer.parseInt((String) this.map.get("numberTo"));
		
    this.showMessage("Counting from "+ numberFrom + " to " + numberTo +" .....");
    this.showSeparator();
    	
    for (int i=numberFrom; i<=numberTo; i++) {
      this.showMessage("Counting "+ i );
    }
		
    this.showError("This time no errors have been produced!");
    this.showAffectedRecords(numberTo-numberFrom+1);
    this.showEnd("That's all folks!");
  }
}

And the output is


And one of the mosrt interesting things is that there is an asynchornous comunication form the server to the client and the count is unordered!
You can see the different types of messages and the colours used to display them.









Comentarios

Entradas populares de este blog

SpringBoot (6) Spring Data JPA (1)

SpringBoot (10) Authentication (1). Server certificate, application.yml and Application.java

Spring Boot (2) Websockets. Subscriptions of only one member