Table of Contents
This chapter gives the fundamentals of web application development with IT Mill Toolkit, concentrating on the basic elements of an application from a practical point-of-view.
If you are a newcomer to AJAX development, you may want to read Section 10.4, “Special Characteristics of AJAX Applications” to gain more insight about application design with IT Mill Toolkit. It explains the role of pages in AJAX web applications, and provides some basic design patterns for applications.
An application made with IT Mill Toolkit runs as a Java Servlet in a Servlet container. The entry-point is the application class, which needs to create and manage all necessary user interface components, including windows. User interaction is handled with event listeners, simplified by binding user interface components directly to data. Visual appearance is defined in themes as CSS files. Icons, other images, and downloadable files are handled as resources, which can be external or served by the application server or the application itself.
Figure 4.1, “Application Architecture” above gives the basic architecture of an application made with the IT Mill Toolkit framework, with all the major elements, which are introduced below and discussed in detail in this chapter.
First of all, an application that uses IT Mill Toolkit must define an
application class that inherits the abstract
com.itmill.toolkit.Application class. The application
class must implement the init() method.
public class MyApplication extends com.itmill.toolkit.Application {
public void init() {
... initialization code goes here ...
}
}
Besides acting as the entry-point in the servlet, the
Application class provides facilities for window
access, execution control, and theme selection. The application API may seem
similar to Java Servlet API, but that is only superficial. IT Mill Toolkit
framework associates requests with sessions so that an application class
instance is really a session object. Because of this, you can develop web
applications much like you would develop desktop applications.
The most important thing in the initialization is the creation of the main window (see below), which any application has. This, and the deployment of the application as a Java Servlet in the Servlet container, as described in Section 4.8, “Setting Up the Application Environment”, are the minimal requirements for an application.
Below is a short overview of the basic elements of an application:
An application always has a main window, as described in Section 4.2, “Managing the Main Window”. An application can actually have a number of such application-level windows, all bound to the same application session, as described in Section 10.1, “Application-Level Windows”. Application-level windows can contain non-native sub-windows, which are essentially floating layout components handled inside the browser.
The user interface consists of UI components that are created and laid out by the application. User interaction with the components causes events (see below) related to the component, which the application must handle. Most components are bound to some data using the Data Model (see below). You can make your own UI components through either inheritance or composition. For a thorough reference of UI components, see Chapter 5, User Interface Components, for layout components, see Chapter 6, Managing Layout, and for composing components, see Section 5.19, “Custom Composite Components”.
Events, and listeners that handle events, are the basis of handling user interaction in an application. Section 3.5, “Events and Listeners” gave an introduction to events and listeners from an architectural point-of-view, while Section 4.4, “Handling Events with Listeners” later in this chapter takes a more practical view.
A user interface can display images or have links to web pages or downloadable documents. These are resources, which can be external or provided by the web server or the application itself. Section 4.5, “Referencing Resources” gives a practical overview of the different types of resources.
The presentation and logic of the user interface are separated. While the UI logic is handled as Java code, the presentation is defined in themes as CSS. IT Mill Toolkit provides a default theme. User-defined themes can, in addition to style sheets, include HTML templates that define custom layouts and other theme resources, such as images. Themes are discussed in detail in Chapter 7, Themes, custom layouts in Section 6.11, “Custom Layouts”, and theme resources in Section 4.5.4, “Theme Resources”.
Field components are essentially views to data, represented in a data model. Using the data model, the components can update the application data directly, without the need for any control code. A field component model is always bound to a property, an item, or a container, depending on the field type. While all the components have a default data model, they can be bound to a user-defined data source. For example, you can bind a table component to an SQL query response. For a complete overview of data binding in IT Mill Toolkit, please refer to Chapter 8, Binding Components to Data.