Folder structure

To develop an application with JVx, a special folder structure is recommended. This simplifies the Build process and separates any dependencies between Client and Server. This structure is to be created as follows:

A conventional structure:

can also be used on request. However, the documentation refers to the recommended structure.

Folder

Description

rad

Contains application- and server-specific files.

apps

Contains all available applications. Only one application is contained in this concrete example.

Contains all libraries which are necessary both on the client and the server.

libs/client

Contains all libraries which are only necessary for the client.

libs/server

Contains all libraries which are only necessary for the server.

src.client

Contains all the sources which are only necessary for the client.

src.server

Contains all the sources which are only necessary for the server.

test

Contains unit tests for the client and server or the libraries.

Once the folder structure has been created, copy the library jvxclient.jar to the folder libs/client and the library jvx.jar to the folder libs/server. Both libraries are contained in the JVx binary package.

Project configuration

Once the configuration steps have been performed, a new project can be created with Eclipse:

File / New / Java Project

Note that the project has to be set up in the application folder firstapp.

Remove the src folder from the Source FoldersSet the folders src.client, src.server and test as Source Folder

Add the jvx.jar library, from the project directory JVxFirstApp/libs/server

The project can now be created

The project is shown in Eclipse as follows:

The src folder can be deleted for consistency, as it is not needed in our application.

Application development

On the server side, the application needs a configuration file for the settings that only concern the application. For the configuration of the server, an extra configuration file is needed. First we create the file for the application:

The security manager for verification of the user names/password when logging into the application.

securitymanager/usersfile

The file with the username/password combinations allowed

lifecycle/mastersession

The class name of the server object which is instantiated when the client performs a login or starts a new MasterSession.

lifecycle/application

The class name of the server object which is instantiated when the application is first accessed. This object is reused every time the application is accessed.

The server configuration file must be stored in the folder ../JVxFirstApp/rad/server.

However, the folder does not appear in our Eclipse project because it is at a higher folder level. The configuration file could be created directly in the file system or we can create a folder link in our project:

File / New / Folder

The configuration file can then be created:

File / New / File - config.xml

The file is filled as follows:

<?xml version="1.0" encoding="UTF-8"?>

<server></server>

The server does not need any special parameters for our application.

For the client, we now need a class of type javax.rad.application.IApplication. A standard implementation of JVx is implemented via com.sibvisions.rad.application.Application. We then derive our client from it and thereby create a class, in the directory src.client, with the following source code:

The standard constructor cannot be used, as each application is started with a technology-dependent launcher. This launcher is already passed to the application in the constructor.

createConnection

The communication protocol is initialised. A DirectServerConnection is sufficient for our application, because both the client and the server are started in the same VM. However, if an application server is in use, a HttpConnection could also be used.

getApplicationName

Sets the application name. This name is needed for the communication with the server, as the latter uses the appropriate application configuration depending on the application name.In our case the application name must be firstapp, because the work directory is also called ../JVxFirstApp/rad/firstapp/. The application name MUST always match the directory name!

It is now time for the first start of the application. To do so, we set up a Runtime configuration:

Run / Run Configurations... / Application - New launch configuration - with the settings:

Parameter

Description

Main class

The technology-dependant launcher is defined here. We use the Swing technology for our application and start a Swing application.

Program arguments

The launcher must be told which application to start. For our Swing application, we can use the mechanism of programme arguments and pass the class name of our application.

The application can now be started and looks as follows:

The first login attempt fails with the following message

Userfile 'users.xml' does not exist!

This file was defined in the config.xml file of the application; however, it has not yet been created. We do so now here:

File / New / File - users.xml

We fill the file with the following:

<?xml version="1.0" encoding="UTF-8"?>

<users> <user name="admin" password="admin"/></users>

Any number of user lines can be entered!

Now the login to the application works perfectly. However, to fulfill our task, we still need the possibility to display or edit a database table. We will now turn to this part of the task.

Create a work screen

Before we create a WorkScreen, we prepare the application to display the WorkScreen. To do so, we extend our FirstApplication class as follows:

This method is invoked form the super class after a successful login. We use this method to extend our menu and our ToolBar.

It is not necessary to undo our changes after logout as this is done by the super class.

doOpenDBEdit

This method is called when the Menu or the ToolBar button are selected.

createMenuItem

Provided by the super class to create menu entries. The first parameter contains the name of the method which is to be called when the menu entry is selected. The second parameter contains the command (ActionCommand) which does not play any role in our case. The text of the menu entry is to be defined in the third parameter and, lastly, the image for the entry is passed.

createToolBarButton

Similar to createMenuItem, except that here a button is created which adjusts itself to the layout of the ToolBar.

UIImage.getImage

Provides a predefined image from the image library of JVx.We use a predefined image for convenience.

Ends the connection to the server for the WorkScreen and closes the Frame.The connection must not be explicitely closed, as this takes place fully automatically by the GarbageCollector. This is however not a drawback in our first application.

createSubConnection

We create our own connection to the server. This has the advantage that a separate Lifecycle object is used on the server. This object contains all objects which are needed by the WorkScreen. Once the WorkScreen is closed, the used memory is released. Moreover, each connection can have special parameters and timeouts. The requested Lifecycle object is defined with the class name: apps.firstapp.frames.DBEdit.

The class we will create later.

Member

Description

connection

The connection to the server, especially for the WorkScreen. A special communication protocol is used in the background. In our case, it is represented by the class DirectServerConnection.

dataSource

The DataSource is independent of the communication protocol and takes care of the data transfer between client and server. The connection defines under which name the server-side object is to be found in the lifecycle object.

The class represents a lifecycle object for a session. In our case, a session begins with the login to the application and ends with the logout. There is exactly one instance of this object for each session. This allows objects to be used for the full duration of the login.

Thanks to the inheritance of apps.firstapp.Application it is very easy to use even application objects.

Method

Description

getDBAccess

Opens a new connection to a HyperSQL database, if this has not already happened.

The class represents the lifecycle object for the DBEditFrame work screen. The objects can only be accessed via the SubConnection of the work screen.

Thanks to the inheritance of apps.firstapp.Session it is very easy to access all Session and Application objects.

Method

Description

getContacts

EEnables the access to the database table CONTACTS. The method name must match the object name of the RemoteDataBook: contacts => getContacts.

The Exception Handling is taken over by the Server.

The application is now fully implemented and ready to run. So as to be able to work with the application, we need a database with the CONTACTS table which we want to access. The configuration of HyperSQL DB is not described in detail in this document, as the examples on the project page are detailed and suffice. In the next chapter, you will find a short summary of the necessary steps.

Create database

The following steps should take place to create and start a HyperSQL DB.

Copy the HyperSQL JDBC-Driver (hsqldb.jar) to the directory../JVxFirstApp/libs/server/