Auto generated CRUD UI - cuba-platform/sample-workshop GitHub Wiki

Under CRUD or standard UI we understand screens that allow you to browse the list of records (browser) and create/edit one record (editor).

4.1 SparePart CRUD UI

Now let’s create the standard browser and editor screens for the SparePart entity.

  1. Open the DATA MODEL section of the left-hand side navigation panel and select the SparePart entity

  2. Click New

  3. Click Generic UI screen

Create screens for SparePart CRUD

  1. GENERIC UI TEMPLATES screen appears. It allows you to specify where to place the screens in the project, what menu item to be used to access the browser screen, should it be a single combined screen for all operations or two separate screens to read the list and create, update and delete an instance.

  2. Select Entity browser, keep the default values and click Create.

  3. Select Entity editor, keep the default values and click Create.

Standard screens for SparePart CRUD

  1. The studio has generated separate screens: browser and editor. You can pick one of them and click Edit in the GENERIC UI section of the navigation panel. Screen designer has WYSIWYG editor, XML and Controller tab to be able to see screen declaration and its Java controller.

Standard screens for SparePart CRUD

  1. Visual components that tightly work with data (tables, dropdowns, etc) are data-aware and connect to the database through datasources. Taking SparePart browser as an example, let’s have a look at data binding. Select the sparepart-browse.xml screen, click Edit and open the Datasources tab. Datasources use standard JPQL queries to load data. In our example the result list of this query will be automatically shown in the main table of the screen, as sparePartsDs is set to the datasoure property of the table.

SparePart Datasources tab

4.2 Client CRUD UI

Then let’s generate the screens for the Client entity.

  1. Open the DATA MODEL section of the navigation panel and select the Client entity

  2. Click New -> Generic UI screen

  3. Select Entity browser, keep the default values and click Create.

  4. Select Entity editor, keep the default values and click Create.

Client CRUD UI

4.3 Mechanic CRUD UI

Similarly, let’s generate the screens for Mechanic.

  1. Open the DATA MODEL section of the navigation panel and select the Mechanic entity

  2. Click New -> Generic UI screen

  3. Mechanic differs from the entities we have just created UI for. It has relation to the system User entity, which is used in CUBA for security reasons. So, our datasource should load the user field along with the simple fields of the mechanic entity. For that purpose CUBA uses views - an XML description of what entity attributes should be loaded from the database. Click the plus button to create a new view and the View designer screen will appear

Mechanic CRUD UI

  1. Studio has automatically generated the Name: mechanic-view, keep it as we will use it for both browser and editor

  2. Our view extends the _local one, which is the system view that includes all the simple (local) attributes. By default all screens use _local view for standard screen generation. It means that references to other entities will not be loaded and shown by default.

  3. Select user attribute and specify the _minimal system view for it; _minimal view includes only attributes, that are specified in the Instance Name of an entity. This view will give us enough information to show an entity in the browser’s table and editor’s field group

  4. Click OK to save the view

Mechanic view

  1. Click Create to save the browser.

  2. Specify the same view for the editor

  3. Click Create to save the editor.

Create Mechanic editor

4.4 Order CRUD UI

Now we need to create screens for the Order entity

  1. Open the DATA MODEL section of the navigation panel and select the Order entity

  2. Click New -> Generic UI screen

  3. Similarly to what we did for the Mechanic entity, click the plus button to create an extended view for the Order entity

  4. Keep the name order-view

  5. Select client and mechanic attributes and specify the _minimal view for both of them

  6. Select the parts attribute, which contains a collection of the SpareParts instances. Adding parts to an order we would like to see only title and description attributes, so tick them

  7. Click OK

Order UI

  1. Click Create to save the browser.

  2. Specify order-view also for the editor

  3. Click Create to save the editor.

next →