Rapid Application Development
If Web applications are built without using tools or libraries for constructing the user interface, the programming effort required to construct the user interface can be significantly more than that required for business logic and database access. Several approaches have been developed to reduce the effort required to build applications:
• Provide a library of functions to generate user-interface elements with mini- mal programming.
• Provide drag-and-drop features in an integrated development environment that allows user-interface elements to be dragged from a menu into a design view of a page. The integrated development environment generates code that creates the user-interface element by invoking library functions.
• Automatically generate code for the user interface from a declarative specifi- cation.
All these approaches have been used for creating user interfaces, well before the Web was created, as part of Rapid Application Development (RAD) tools, and are now used extensively for creating Web applications as well.
Examples of tools designed for rapid development of interfaces for database applications include Oracle Forms, Sybase PowerBuilder, and Oracle Application Express (APEX). In addition, tools designed for Web application development, such as Visual Studio and Netbeans VisualWeb, support several features designed for rapid development of Web interfaces for database backed applications.
We study tools for construction of user interfaces in Section 9.5.1, and study frameworks that support automatic code generation from a system model, in Section 9.5.2.
Tools for Building User Interfaces
Many HTML constructs are best generated by using appropriately defined func- tions, instead of being written as part of the code of each Web page. For example,address forms typically require a menu containing country or state names. In- stead of writing lengthy HTML code to create the required menu each time it is used, it is preferable to define a function that outputs the menu, and to call the function wherever required.
Menus are often best generated from data in the database, such as a table containing country names or state names. The function generating the menu exe- cutes a database query and populates the menu, using the query result. Adding a country or state then requires only a change to the database, not to the application code. This approach has the potential drawback of requiring increased database interaction, but such overhead can be minimized by caching query results at the application server.
Forms to input dates and times, or inputs that require validation, are similarly best generated by calling appropriately defined functions. Such functions can output JavaScript code to perform validation at the browser.
Displaying a set of results from a query is a common task for many database applications. It is possible to build a generic function that takes an SQL query (or ResultSet) as argument, and display the tuples in the query result (or ResultSet) in a tabular form. JDBC metadata calls can be used to find information such as the number of columns and the names and types of the columns in the query result; this information is then used to display the query result.
To handle situations where the query result is very large, such a query result display function can provide for pagination of results. The function can display a fixed number of records in a page and provide controls to step to the next or previous page or jump to a particular page of the results.
There is unfortunately no (widely used) standard Java API for functions to carry out the user-interface tasks described above. Building such a library can be an interesting programming project.
However, there are other tools, such as the JavaServer Faces (JSF) framework, that support the features listed above. The JSF framework includes a JSP tag library that implements these features. The Netbeans IDE has a component called VisualWeb that builds on JSF, providing a visual development environment where user interface components can be dragged and dropped into a page, and their properties customized. For example, JSF provides components to create drop- down menus, or display a table, which can be configured to get their data from a database query. JSF also supports validation specification on components, for example to make a selection or input mandatory, or to constrain a number or a date to be in a specified range.
Microsoft’s Active Server Pages (ASP), and its more recent version, Active Server Pages.NET(ASP.NET), is a widely used alternative to JSP/Java. ASP.NET is similar to JSP, in that code in a language such as Visual Basic or C# can be embedded within HTML code. In addition, ASP.NET provides a variety of controls (scripting commands) that are interpreted at the server, and generate HTML that is then sent to the client. These controls can significantly simplify the construction of Web interfaces. We provide a brief overview of the benefits that these controls offer.
For example, controls such as drop-down menus and list boxes can be asso- ciated with a DataSet object. The DataSet object is similar to a JDBC ResultSet object, and is typically created by executing a query on the database. The HTML menu contents are then generated from the DataSet object’s contents; for exam- ple, a query may retrieve the names of all departments in an organization into the DataSet, and the associated menu would contain these names. Thus, menus that depend on database contents can be created in a convenient manner with very little programming.
Validator controls can be added to form input fields; these declaratively spec- ify validity constraints such as value ranges, or whether the input is a required input for which a value must be provided by the user. The server creates ap- propriate HTML code combined with JavaScript to perform the validation at the user’s browser. Error messages to be displayed on invalid input can be associated with each validator control.
User actions can be specified to have an associated action at the server. For example, a menu control can specify that selecting a value from a menu has an associated server-side action (JavaScript code is generated to detect the selection event and initiate the server-side action). Visual Basic/C# code that displays data pertaining to the selected value can be associated with the action at the server. Thus, selecting a value from a menu can result in associated data on the page getting updated, without requiring the user to click on a submit button.
The DataGrid control provides a very convenient way of displaying query results. A DataGrid is associated with a DataSet object, which is typically the result of a query. The server generates HTML code that displays the query result as a table. Column headings are generated automatically from query result meta- data. In addition, DataGrids provide several features, such as pagination, and allow the user to sort the result on chosen columns. All the HTML code as well as server-side functionality to implement these features is generated automati- cally by the server. The DataGrid even allows users to edit the data and submit changes back to the server. The application developer can specify a function, to be executed when a row is edited, that can perform the update on the database.
Microsoft Visual Studio provides a graphical user interface for creating ASP pages using these features, further reducing the programming effort.
See the bibliographic notes for references to more information on ASP.NET.
Web Application Frameworks
There are a variety of Web application development frameworks that provide several commonly used features such as:
• An object-oriented model with an object-relational mapping to store data in a relational database (as we saw in Section 9.4.2).
• A (relatively) declarative way of specifying a form with validation constraints on user inputs, from which the system generates HTML and Javascript/Ajax code to implement the form.
• A template scripting system (similar to JSP).
• A controller that maps user interaction events such as form submits to ap- propriate functions that handle the event. The controller also manages au- thentication and sessions. Some frameworks also provide tools for managing authorizations.
Thus, these frameworks provide a variety of features that are required to build Web applications, in an integrated manner. By generating forms from declarative specifications, and managing data access transparently, the frameworks minimize the amount of coding that a Web application programmer has to carry out.
There are a large number of such frameworks, based on different languages. Some of the more widely used frameworks include Ruby on Rails, which is based on the Ruby programming language, JBoss Seam, Apache Struts, Swing, Tapestry, and WebObjects, all based on Java/JSP. Some of these, such as Ruby on Rails and JBoss Seam provide a tool that can automatically create simple CRUD Web interfaces; that is, interfaces that support create, read, update and delete of objects/tuples, by generating code from an object model or a database. Such tools are particularly useful to get simple applications running quickly, and the generated code can be edited to build more sophisticated Web interfaces.
Report Generators
Report generators are tools to generate human-readable summary reports from a database. They integrate querying the database with the creation of formatted text and summary charts (such as bar or pie charts). For example, a report may show the total sales in each of the past 2 months for each sales region.
The application developer can specify report formats by using the formatting facilities of the report generator. Variables can be used to store parameters such as the month and the year and to define fields in the report. Tables, graphs, bar charts, or other graphics can be defined via queries on the database. The query definitions can make use of the parameter values stored in the variables.
Once we have defined a report structure on a report-generator facility, we can store it and can execute it at any time to generate a report. Report-generator systems provide a variety of facilities for structuring tabular output, such as defining table and column headers, displaying subtotals for each group in a table, automatically splitting long tables into multiple pages, and displaying subtotals at the end of each page.
Figure 9.12 is an example of a formatted report. The data in the report are generated by aggregation on information about orders.
Report-generation tools are available from a variety of vendors, such as Crys- tal Reports and Microsoft (SQL Server Reporting Services). Several application suites, such as Microsoft Office, provide a way of embedding formatted query results from a database directly into a document. Chart-generation facilities pro- vided by Crystal Reports, or by spreadsheets such as Excel can be used to access data from databases, and generate tabular depictions of data or graphical depic- tions using charts or graphs. Such charts can be embedded within text documents.
Figure 9.12 A formatted report.
The charts are created initially from data generated by executing queries against the database; the queries can be re-executed and the charts regenerated when required, to generate a current version of the overall report.
In addition to generating static reports, report-generation tools support the creation of interactive reports. For example, a user can “drill down” into areas of interest, for example move from an aggregate view showing the total sales across an entire year to the monthly sales figures for a particular year. Such operations were discussed earlier, in Section 5.6.