đ
CUBA Studio 12 Quick Start - YouTube
Channel: Jmix Framework
[2]
Hello! And welcome to the CUBA Platform Quick Start Video.
[8]
CUBA Platform is an open source framework based on the well-known Spring framework.
[13]
The purpose of CUBA is to streamline the development process of business applications.
[19]
This quick start video covers the following topics
[40]
As an example we will create a simple
[42]
but fully functional version of an application that will help
[45]
with session planning for a conference.
[47]
The video will be just enough for you to start developing with CUBA
[52]
For this video, in addition to the CUBA Platform framework
[56]
we will use a plugin for IntelliJ Idea - CUBA Studio
[63]
Letâs create an empty CUBA project and name it SessionPlanner
[68]
We will use Java 8 as a default JDK
[71]
The CUBA framework uses Gradle as a build tool
[77]
Now we will create JPA classes along with business rules
[81]
like mandatory fields, unique fields and relations
[84]
The business domain model has only two classes (also called entities): Speaker and Session
[94]
First, we need to create the Speaker entity
[98]
It has three fields: first name (mandatory)
[105]
last name (optional)
[110]
and email (mandatory and unique)
[114]
Letâs add a validation for the email field
[117]
CUBA provides an ability to specify
[120]
a proper entity display in the string format in the UI - âInstance Nameâ
[125]
For the speaker, we will select both first and last name
[131]
If we will have a look at the Java tab of the entity designer
[134]
we can see just a JPA-annotated java class
[138]
Letâs move further and create the Session entity and link it to our Speaker class
[145]
First, define an attribute Topic - a mandatory string
[150]
After that, we will add session start and session end date and time attributes
[156]
Session end will be a calculated value, being one hour from the start
[165]
Now we add a reference to a speaker, the relation is many-to-one
[169]
Weâll define association field called speaker that references to the speaker class
[175]
For the reference field, letâs use dropdown+lookup type
[179]
In addition to this, we create a description field that will contain a session description
[186]
Now it's time to create a calculated attribute - a sessionâs end date
[193]
In CUBA, you can add field calculation logic using entityâs lifecycle callbacks
[199]
You need to create a method and mark it with a proper java annotation
[203]
The method will be invoked automatically
[206]
Letâs add a method that will be invoked on âPrePersistâ lifecycle phase
[210]
Name the method âupdateEndDateâ and mark it with @PreUpdate annotation in addition to @PrePersist
[219]
We will create a separate method for the session end time calculation, to reuse it in the application later
[229]
In this method, we just add one hour to an input parameter
[239]
And now we just add method invocation to the lifecycle method
[248]
Our domain model entities have been created
[251]
Now we need to generate scripts to create a database
[261]
By default, CUBA Studio uses HSQL database during the development stage
[266]
To generate scripts for the database creation,
[269]
you need to select CUBA - Generate Database Scripts menu
[279]
To apply those scripts and create the database, just select CUBA - Create Database menu
[286]
Apart from application tables, CUBA creates system tables where we store information about users, roles, tasks, etc
[302]
CUBA Studio contains a UI screen generation wizard
[306]
that helps us to create basic, but useful UI screens:
[310]
The browser - to show the list of entities in a grid
[314]
and the editor - to edit one entity instance using a form-like user interface
[320]
First, we will create screens to work with speakers
[323]
Since this entity is pretty simple,
[326]
we can accept the default parameters for the screen creation
[331]
As you can see, each screen consists of two parts
[335]
a controller, written in java, which is responsible for internal screen logic and events handling
[341]
and an XML layout that defines the screen appearance
[346]
Please note âDATAâ section in the XML
[349]
it defines how the data is fetched from the database
[353]
You can easily navigate between screens and linked entities with CUBA Studio
[361]
Now letâs create a browser and an editor for sessions
[367]
Here we need to stop for a while and explain some bits of CUBA
[373]
Letâs talk about âBrowse viewâ and âEdit viewâ fields
[377]
In the CUBA Platform, Entity View specifies which fields will be fetched from the database
[385]
For the session entity, we will not expose its end date for editing
[389]
but leave it for viewing. Letâs get started
[393]
We will create a separate view for the âSessionâ entity to include speaker reference for browser screen
[404]
While creating a view for a session editing
[406]
we will deliberately exclude the end date end from the view
[409]
so the screen generator will not create a widget for it
[425]
As you can see, there is no âEnd Dateâ field in the editor screen
[429]
Letâs update the âdescriptionâ field to use a multi-line editor
[440]
And now we are able to see the sessionâs end date in the browser screen
[446]
Now we can run the application in development mode from the IDE
[455]
Just press âRunâ in the IDE to start the application
[459]
After some time you can access the application using the browser
[467]
Letâs open the URL and log into the application using the username âadminâ
[473]
The password is âadminâ by default
[477]
Letâs add some test data to the application:
[480]
first, a couple of speakers, then two sessions scheduled for the rest of the week
[489]
As you can see, email validation works as expected
[499]
Now letâs add a couple of sessions for today and tomorrow
[511]
Generated screens are good for basic operations,
[514]
but in the real world UI is usually more complex
[517]
Letâs add a calendar view to browse visits in addition to the grid view
[526]
For the browser screen, weâll add tab control, put a calendar on it and provide a functionality to edit and reschedule sessions using this calendar
[537]
Letâs add tab control and two tab pages to the sessions browser screen
[555]
It is recommended to assign an id for each control, so we can reference to it
[570]
Now letâs set a caption for each tab
[580]
Letâs drag the sessions table control to the second tab
[584]
and expand tab control to the whole screen
[587]
by setting âExpandâ property in the parent component
[591]
The next step is to put a calendar control on the first tab, assign an id and expand it
[610]
In CUBA, UI components are bound to entities and their properties
[614]
We will bind the calendar to the data collection fetched in the screen and bind:
[620]
startDateProperty to a sessionâs start Date
[623]
endDateProperty to a sessionâs endDate
[628]
captionProperty to a sessionâs topic
[631]
and descriptionProperty to a sessionâs description
[635]
In addition to the visual designer you can use the XML markup editor
[639]
Let's make the calendar to show only working hours and add navigation buttons
[651]
We can reopen the form to see the changes - the CUBA framework supports hot reload for screens
[658]
Now we can see sessions displayed on the calendar
[662]
Now letâs invoke session editor screen when we click on an event in the calendar
[676]
When we interact with the UI, events are generated
[679]
We can subscribe to those events to handle them
[682]
Letâs handle a click on a calendarâs entry
[686]
We need to invoke the editor screen
[688]
For screen manipulations, CUBA provides a screen builder API that we will use
[694]
Letâs add ScreenBuilder class to the screen controller
[698]
With ScreenBuilder API
[700]
Invoking a screen becomes a chain of method calls
[703]
We need the editor for the session class with this as a parent screen
[708]
Then we want to edit the session entity received within the event object
[713]
The screen will be opened in the dialog mode
[724]
When the editor is closed, we need to reload all data on the browser screen
[729]
After that we should show the editor that we have just built
[736]
Letâs reopen the screen and invoke the editor
[741]
As you can see, we need to refine the session editor dialog to make it look better by adjusting its width and height
[757]
Letâs reopen the screen again and see the changes
[760]
Now it's time to add some business logic to our application
[764]
In this section we will use CUBA Studio to create a service
[767]
that implements business logic and then use this service in a screen
[772]
It will be a service for session rescheduling
[774]
that will check that one speaker doesnât have two sessions at the same time
[779]
Right-click on the service node in the CUBA project tree
[783]
and create a SessionService interface and SessionServiceBean implementation
[789]
Create a method in the interface and implement it in the ServiceBean
[793]
The method will accept a session and a new session date and time
[801]
If we were able to reschedule the session
[803]
we save it with new start date and time
[806]
and if not - just return false as the service execution result
[811]
We will use a CUBAâs API for data access - DataManager class
[816]
Letâs add it into the service first and then use it in the method
[824]
With DataManager we create a JPQL query to check
[829]
if there are any sessions scheduled for the speaker in a defined time span
[833]
and add parameter values to it
[862]
Then we check the query result and, depending on it
[865]
we update the session with a new start date
[868]
or just exit from the method with a corresponding result
[872]
The service is ready, now letâs add it to the session browser screen
[876]
It will be invoked for the drag-and-drop event in the calendar
[882]
In the method that is subscribed to drag-and-drop event
[885]
we add some code to extract the session entity from the calendar event
[890]
and then invoke the service to reschedule this session
[894]
If the session cannot be rescheduled
[896]
we show on-screen notification using notification API that we will add to the screen
[924]
To have the new service redeployed, we need to restart the application
[939]
After restarting we can open sessions calendar - and voila!
[944]
We have a drag-and-drop scheduling functionality for the calendar
[948]
Letâs see it if works
[950]
We can add an extra session and try to reschedule it
[974]
In this section we will customize standard captions in the application, adding some branding
[979]
In CUBA, you can update resource files and override standard text
[984]
Letâs update text according to the application business domain - conference planning
[1001]
With CUBAâs hot deploy feature, all we need to do is log in to the application again to see the changes
[1012]
This framework comes with a marketplace that contains plenty of components
[1016]
so you can easily add useful features like charts or maps support to the existing application
[1022]
You can install those components right from the studio using the âMarketplaceâ menu
[1037]
The CUBA framework provides a lot of useful APIs to help you create business applications quickly
[1044]
This quickstart shows only the basics of the CUBA framework and CUBA Studio
[1049]
You can find more examples and tutorials on our website: cuba-platform.com
You can go back to the homepage right here: Homepage





