Scaffolding is a mechanism which helps programmers and/or designers in creating a starting point for further development. It could generate various artefacts, but in ODRA eIDE2 is utilized for building a web GUI for a business class. The GUI supports CRUD (Create, Retrieve, Update, Delete) operations using a client-side library called Knockout.js.
At the beginning make sure that you have all necessary parts correctly installed:
The current version of the scaffolding works with any business class implemented in SBQL on the ODRA platform. Existing version supports only simple types, but we are going to expand it in the future.
Let’s start with a slightly modified (remove all methods and the Products
variable) Product class from the tutorial #2:
module ProductMod { class ProductClass { instance Product: { name: string; description: string; manufactureDate: date; stockItems: integer; } } }
As you can see, the IDE reports a warning (a yellow underlining) regarding a missing identification field. This is caused by the fact that the mechanism requires two special fields in a processed class:
id: integer
;name: string
.Let’s see what will happen if we start the process right now. Click the small icon located at the margin in the class instance line and then double click on the link.
As we could expect the scaffolding process reported an error message.
Fortunately fixing this is really simple. We can manually add a required line of code (id: integer;
) or use an another technology implemented in the IDE (a quick fix) which will automatically do it for us: hoover over the warning and click the link as presented below:
As the result a required code has been added to the class. A similar solution can be used in a case of missing name field.
Right now we are ready to scaffold some GUI – do it by clicking the previously mentioned icon.
After a short while we can observe the results of the operation (a couple of new files and folders added to the project):
RouteClass
(each instance stores a single routing rule) and WebParamType
(utilized for passing parameters from the web);Routes
which is an extent for all the rules;createRoutes()
method which puts global routing rules into the DB;Product
. It is responsible for:
Product
;webXXX
. Please note that the methods are referenced by Data routing rules (inside the createRoutesForProduct()
method));createRoutesForProduct()
method);seedProduct()
method);createRoutesForProduct()
method);To test the GUI we need to do a couple of things. Let’s begin with putting all required data (the business class, the controller and the routing rules) into an ODRA DB:
GlobalMod.createRoutes()
;ProductControllerMod.createRoutesForProduct()
;ProductControllerMod.seedProduct()
;Now, when the ODRA DB contains all required data, we should focus on the web part. Point the webODRA to the generated web root folder. We can do this by passing a dedicated parameter (webRoot
) to the main class. This could be achieved in many ways. One of them is to modify the webODRA - only.bat file. At the very end of the file, after the com.mt.odra.webodra.OdraWebServer
add the webRoot
parameter referencing the generated directory (in my case it is: webRoot="C:\Users\Mariusz\workspace-test\Sbql Test\WebRes"
).
Finally start the webODRA by executing the modified file webODRA - only.bat. If everything was fine you should see a cmd window with logging information.
Point your web browser to: http://localhost:8080/
Select the Products link (at the very top of the page) and enjoy the Index view.
Try yourself all generated functionalities by clicking appropriate buttons.
Remember that the generated files are just a starting point and they could be modified. To make the process easier you can install additional plugins for Eclipse, e.g. Eclipse Web Developer Tools.