SpringBoot (13) Let's start (1/10). Introduction to defining menu items.

 0. Introduction

Four menu item types are used:

  1. Menu/submenu: Can have children. They are the parent of a tree. You can go to children. No actions can be performed. No URL can redirect
  2. ActionForm: Execute the method of a class and can have parameters. The parameters can be displayed in a form to change any value. A URL is needed
  3. CRUDForm : To insert/update/delete objects from a class. A URL is needed.
  4. Grid: For displaying database elements in a grid.
The file "src/main/resources/config/menus/menus.yml" contains the menu configuration an definition
The most important common fields are:
  1. id: must be supplied and must be únique. Typical values "1","1-1","1-2","1-2-1", you can use any id, but it should be easy to 
  2. name: Is the description in the menu item
  3. accessLevel: Is the minimum access level required for the user to be executed or displayed. By default its value is 1 (0=No permissions required, 1: see, 2: list, 3: edit,4:insert, 5: delete, 6: admin)
  4. specialRole: A string identifying a special role as "ADMIN", "TERCERS", "TERRIRORI". To access this menu, the users must have the special role.
  5. allUsers: If true, all users can access this menu item.
Here is a YAML file where the fields idname, and accessLevel are used. Also specialRole field is used in the first element (line 4)

1
2
3
4
5
6
menus:
  items:
  #--- Negociats: Nivell 0
    - { id: 1, name: Secretaria,  accessLevel:1, specialRole: SECRETARI,  idFills: [1-1, 1-2] } 
- { id: 2, name: Estadística, accessLevel:1, idFills: [1-1-1, 1-1-2] } - { id: 1-1, name: Decrets ENI, accessLevel:4, idFills: [1-1-1, 1-1-2] }

1. Menu/submenu

The menu/submenu element is the first type of element and  has a field that is a list of children's ids that you can access. This field is idFills and you can see it in lines 4, 5, and 6. In this case, the menu with id 1 has 2 children with ids "1-1" and "1-2"

2. ActionForm

The action form is the second type of menu element and must have also these fields:
  1. href: it is discouraged to use this field, as it encloses the rest of the following fields. Internally, the following fields are combined to build the href field.
  2. url: where the Spring controller  (webController.java) must have a method with a @GetMapping or @RequestMaspping annotation whose value is this url field. Usually, the URL is "/generalActionForm"
  3. title: A title of the form
  4. subtitle: A subtitle of the form for additional information
  5. processClassName: A class name in the package ximo.actions that will be executed when the form is submitted. This class must have a main method.
  6. lFields: A list of fields that will be displayed in the form and provides the execution parameters of the class. Each field can have these fields:
    1. name: must be unique. 
    2. label: that appears in the form for this field
    3. value: default value.
    4. component: The component type may be SELECT, NUMBER, HIDDEN, INPUT, RADIO, CHECK, FILE.
    5. optionValues: Only for components of type SELECT for instance "1,2,3,4"
    6. optionText: Only for components of type SELECT for instance "BIG,MEDIUM,SMALL"
    7. accept: Only for components of type FILE, for instance, "image/png, image/jpg" or  ".doc,.docx,.xml"
Here are 2 examples of defining the same action form. The first is more structured but the second includes all references to the href that is discouraged as it is more error prune, so it is commented wit "#"

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
menus:
  items:
    - { id: 6-1, name: MargaPDFSplit3, specialRole: ADMIN, url: /generalActionForm,  
        processClassName: A01_ActionMarga_IRPF_Split_Alcalde_Signature,
        title: Trocejar un PDF en grups de 2 pàgines i ficar segell i firma Alcalde,
        subtitle: Tresoreria-IRPF,
        lFields: [ 
          { name: resource,  label: Document Sencer,       component: FILE,  value: /home/eduard/PDF/190_2022/190_IRPF_2022.pdf,     accept: .pdf  },
          { name: imgAlc,    label: Fitxer Firma Alcalde,  component: FILE,  value: /home/eduard/PDF/190_2022/firma_sergi.png,       accept: ".png,.jpg,.jpeg"  },
          { name: imgSegell, label: Segell Tresoreria,     component: FILE,  value: /home/eduard/PDF/190_2022/segell_tresoreria.png, accept: ".png,.jpg,.jpeg"  },
          { name: prova,     label: Prova (sols 2 rebuts), component: CHECK, value: prova }
        ]  
      }
    #- { id: 6-1, name: MargaPDFSplit3, specialRole: ADMIN,                        
    #        href: "/generalActionForm?processClassName=A01_ActionMarga_IRPF_Split_Alcalde_Signature\
    #              &title=Trocejar un PDF en grups de 2 pàgines i ficar segell i firma Alcalde\
    #              &subtitle=Tresoreria-IRPF\
    #              &field={'name':'resource', 'label':'Document Sencer', 'value':'/home/eduard/PDF/190_2022/190_IRPF_2022.pdf','accept':'.pdf','component':'FILE' }\
    #              &field={'name':'imgAlc', 'label':'Fitxer Firma Alcalde', 'value':'/home/eduard/PDF/190_2022/firma_sergi.png','accept':'.png,.jpg,.jpeg','component':'FILE'}\
    #              &field={'name':'imgSegell', 'label':'Segell Tresoreria', 'value':'/home/eduard/PDF/190_2022/segell_tresoreria.png','accept':'.png,.jpg,.jpeg','component':'FILE'}\
    #              &field={'name':'prova', 'label':'Prova (sols 2 rebuts)', 'value':'prova','component':'CHECK'}" }              
    

3. The CRUD Form

It is the third type of menu element and represents a form for database elements. It must have these fields (and also the common fields):
  1. modelClassName: It is the class whose elements are stored in the database and we want to add, delete, modify, or look up
  2. pkg: The java package where the class is stored
  3. action: a word that can be "crud" or a combination of the letters or this word for instance "cu", "r", "u", "c". CRUD is the acronym for Create-Read-Update-Delete.
  4. where: is a JPA expression. Note that the $DNI$ is used for getting the DNI from the certificate CN. For instance "a.DNI='$DNI$' AND a.plaza.id=1"
  5. opts: is formed by a combination of words separated by commas. It is used in the thymeleaf forms. By now, "rebutx,admin" represents the admitted options, the first is for invalidating some information included by the user and the second is for accessing only the administrator.
Here are some examples of CRUD forms:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
menus:
  items:
    - { id: 3-1, name: Autobaremació, url: '/crud',
         modelClassName: RHPlazaPersona, pkg: ximo.xotherapps.model.rrhhv3, 
         action: u, allUsers: true, where: "a.DNI='$DNI$' AND a.plaza.id=1"
      }
    - { id: 3-2, name: Autobaremació amb rebutx, url: '/crud',
         modelClassName: RHPlazaPersona, pkg: ximo.xotherapps.model.rrhhv3, 
         action: u, allUsers: true, where: "a.DNI='$DNI$' AND a.plaza.id=1", opts: 'rebutx,admin'
      }
    - { id: 3-3, name: Definició Places, url: '/crud',
         modelClassName: RHPlaza, pkg: ximo.xotherapps.model.rrhhv3, 
         action: u, allUsers: false, where: "a.id=1"
      }
    

4. Grid

This is the fourth menu element type and displays the database elements in tabular form.
It shares with the CRUD Form element these fields: modelClassNamepkg, and it is in construction.

A simple example is:

1
2
3
4
5
6
7
8
menus:
  items:
    - { id: 8-2, name: Prova AG-Grid,               url: '/ag-grid',
        #modelClassName: KKK, pkg: ximo.xproves,
        modelClassName: RHPlaza, pkg: ximo.xotherapps.model.rrhhv3,
        title: Prova AgGrid,
        subtitle: Informatica
      }      

Here is an example of the displayed menu




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