Step 4 Create A New Menu Item
Now that you have a window, create a new menu item that allows the user to open this window. To do this, find and open the ApplicationStartup.java file using the Project Explorer.
When you open this class, you can see that this is not an empty class but a source generated by the archetype. The init
method of this class will run when the system is started (more precisely, when the application server loads your application). It’s a good idea to do some resource-intensive tasks here and upload the caches that will not change when the program is running. As a result of this, the first page will be displayed very quickly when the user opens the application because all the necessary data will be in the server’s memory.
The class contains dedicated caches used by the framework. It performs various tasks, e.g. keeps track of pages and menu items, to name a few. Pages and menu items are stored in these caches. Also, individual items are given a unique ID. Such tasks can be performed by using a method for each one. The framework handles these methods and automatically executes them if need be.
Register your page to the framework
You can do this by looking for the createPages
method in the class. In the method, you will find a row that has been generated by the archetype. This row is responsible for registering the main page to the framework. Create a similar row to the one registering the recently completed page. Specify welcomePage
as the unique ID for the registered page. Later on, you can reference the page as follows:
This code snippet registers your page to the framework. The first parameter is a text value that is the unique page ID in the application. Specify any value here. The only constraint is that this value has to be a unique one throughout the whole application.
The second parameter is the UI class you use to display the page. In this case, since we have only one UI class in this application, we use this.
The third parameter is the class that creates the page. In this example, this is the class we created in the first paragraph.