Step 8 Parameters

Our application is almost complete. The last step is to modify the ApplicationStartup class generated by the maven archetype. In applications created by the JBStrap framework, the Startup class is the application’s initialization point. Here, you have to configure the framework’s parameters, add the pages to the framework or create the menus.

Setting the application parameters

In the ApplicationStartup class, look for the parameterSettings() method and change it so that it contains the following code:

The method already contains the majority of the settings, but there are some that you need to configure manually. These settings include:

  • Setting the application’s starting page. Do this by setting the ENTRY_POINT parameter. Specify the ID of the page you want to set as the starting page. In this example, we want to display the orders page as the starting page, so specify ApplicationConstants.ORDERS_PAGE.

  • Next, we have to specify the application’s title. Use the APPLICATION_TITLE parameter to do this. Specify the text here that you want to display in the browser’s address bar.

Now we are ready with the parameters, but we still have to create the pages in the application.

Creating pages

Pages are created by using the createPages() method in the ApplicationStartup class. Modify the method, so the contents are the following:

Since there are three pages in the application, we have to write three lines. All lines are the same, only their parameters are different.

Register the pages in the JBStrap framework by using the JBStrap.addPage() method. The first parameter of the method is the unique ID of the page that you can use later to reference the page. The second parameter is the UI class used to display the page. In this example, there is one UI only, so you have to specify this UI. The last parameter is the page class to be registered in the framework. Specify the previously created classes.

The pages are now registered, you only have to create the menu.

Creating menus

Use the createMenus method to create menus. Later on, you can use this menu to build a NavBar component or a MenuBar component. The NavBar is the vertical navigation bar on the left side of the screen. The MenuBar is the horizontal menu on the top of the screen. In the current example, we use the menu to build the NavBar component.

First, create the menu and name it. In the JBStrap framework, there can be multiple menus and you have to use their names to reference them. Use the JBStrap.createMenu("mainMenu”) method to create the mainMenu.

Add individual menu items to this menu. Do this by calling the JBStrap.addMenuItem() method. The method’s first parameter is the menu name. The second parameter is the menu item name. The parameter accepts any text value. The third parameter is the menu item icon. Note that both the NavBar and the MenuBar components can only display an icon on the top level. If you put the menu item to a lower level, this setting will be ignored.

The next parameter is the menu item text. Users will know what the menu item stands for. In our example, we retrieve this text from the file.

Now you have to specify what should happen when users click on the menu item. Here you can choose from among one of the values of the MenuOperation enum. It can either be OPEN_PAGE or CUSTOM. If you specify CUSTOM , the custom implementation is executed when clicking on the menu item. If you choose OPEN_PAGE , you have to provide the page’s unique ID in the next parameter. The framework automatically opens it when clicking on the menu item. We use the OPEN_PAGE , because we want the page to open when users click on a menu item.

In the last parameter, specify the unique ID of the page.

The application is now ready. Compile and deploy it, and it is ready to use.