screenDemo application for Ujorm and Wicket

The sample CRUD application to hotel reservation
Author: Pavel Ponec, 2013-2014
Document license: Creative Commons BY-ND


The java library Ujorm was introduced in 2008 under the old name UJO Framework. Since then, five years have passed and the source code has been modified many times but the basic idea - accessing to the properties by constants called keys - remains. It is true that the HashMap object uses a similar approach, but the keys in Ujorm are a little different:

Features common to Ujo and the HashMap class:

It is obvious that accessing data via the Ujo keys is less comfortable than accessing through the getters and setters. The question is, what is the practical use then? The simple answer is that the Ujo objects are useful wherever we need a reference to attributes of a domain object (not its value). Because such claims are insufficiently illustrative, I decided to present a small web project for hotel booking. Graphical interface is rendered by the popular Apache Wicket framework. The core of the application consist of the dialogs and preview tables, all data are provided from a relational database using an ORM module from the Ujorm library. During the development, several classes have been optimized for general use so I moved them into a separate module called ujo-wicket. All the Java libraries have an open license and they are available at the central Maven repository.

Class Model

The following figure describes the use of class model of the persistent classes:


Entity Booking is a relation of type M:N between the Hotel and the Customer. The customer can therefore book an accommodation in more hotels, and one hotel reservation holds more customers. To simplify, we do not care about the capacity of the hotel. To make the data model more interesting, we should add next entity called City, which is an attribute of the Hotel, however the project have no administration for the City entity.

Hotel table list

Table with a list of hotels in a picture below:


Table probably won’t surprise the standard users of internet applications, it handles paging, sorting columns and booking the selected hotel. Data are retrieved from a relational database using the SQL statements. The source code is more interesting, the individual table columns (components) provides a factory method - according to the Ujo keys, wow :-). Some CSS styles were also assigned by the key’s attribute type. The table component is built using the source code below:


And that's it. The selection of database rows are restricted by an object Criterion, which is passed to the constructor of the UjoDataProvider class, where the class provides an instance of the table component, too. An ORM configuration with a database connection provider is obtained from the HotelsApplication class. We do not have to care about sorting column tables now, because each column is mapped to a database column and then a click event generates the necessary SQL query automatically.

Editing form


Nearly same as the table columns, this dialog form lines are also created using a factory method according the Ujo keys keys, while the keys provide an additional input, a data validator. All the texts are localized using the tools of the Wicket. Sample source code follows:


It remains only to add some Java code to save the modified hotel on the Save button. In our project we are going to use some methods/services managed by the Spring framework.

Getters and setters are not required in any Ujo class, but putting them in will make more transparent source code in service layer implementations. The NetBeans IDE has an available plugin for generating the required methods by keys, similar plugin for Eclipse is missing yet, perhaps it will be a challenge for new fans :-).

Database queries

Database requirements are modelled using the Key object, which provides special methods to create a new object called Criterion used for describing the logical conditions. Two Criterions can be joined to a binary tree. See a simple code to get a logged user:

Find Customer

For more information see the document Ujorm User Guide.

Application events

On some user action, a related component sends an event to another component using the method Component.send(..) with a payload argument type of UjoEvent. Recipients can detect such an event inside a method called Component.onEvent (...). Request to view a modal dialogue can be distinguished by setting a flag UjoEvent.showDialog with a value true. Sample of event hotel management are as follows:

Hotel Events

Domain object

To be clear, I’m enclosing a source code of persistent hotel entity:


Database connection

Application Demo-Hotels uses the H2 database running under in-memory in the default configuration. A database structure create ORM based on the object model and configurations. To change the database connection can be modified:

  1. class DatabaseMapping annotation parameters: user, password, jdbcUrl, dialect
  2. in the classroom DatabaseMapping annotation parameters: jndi + dialect
  3. in the classroom DatabaseConfig can be set with external XML configuration tags: user, password, jdbcUrl, dialect
  4. in the classroom DatabaseConfig can be set with external XML configuration tags: jndi + dialect
  5. used in dialect can also overlay method: SqlDialect.createConnection(..)
  6. data for a table can also change the overlay method UjoDataProvider.iterator(first, count) by the actual implementation

where each solution with higher number overlaps the previous solution. I have put two files into the project to connect to the MySQL and PostgreSQL databases type:

which can serve as a template to connect to an own database. I remind you that the XML configuration can be activated in the DatabaseConfig class.


Application Demo-Hotels was created in a hope that some parts of the source code would clarify the using of Ujo objects to our readers, but the application itself is not intended for commercial use. If you have the impression that some parts of the code can be handled better or that the project can still continue working, you may be right. All graphic components are descendants of the Wicket framework so you can extend it for your specific needs. Some of the ideas were inspired by the WebFort project from the end of 2008, but I cannot exclude the possibility that a similar code did not appear ever before. Thank you for your constructive feedback.