Previous Next Contents Index


Using Wizards to Generate Project Files

This chapter describes the Netscape Application Builder code generation wizards that help you perform common tasks associated with building a Netscape application. The wizards provide a quick method for automatically generating and linking together files needed for advanced application features.

The following topics are described in this chapter:


About the Wizards
Netscape Application Builder provides easy-to-use code generation wizards to create sets of HTML and JavaServer pages, servlets, and database queries. To use these wizards most effectively, it is best to think of your application in terms of activities, and from there, map each activity to the use of one or more Wizards.

The tasks common to most applications involve interactions between application users and the Servlets and JSPs that make up the application's business logic. Netscape Application Builder provides two generic wizards to help you create the files necessary for gathering input from a user (the Input wizard) and giving information to the user by way of an HTML template (the Results wizards). There is also one wizard for generating input forms and output reports from a relational database (the Database Forms wizard), and one for implementing a login page with optional password validation (the Login wizard).

Wizards are invoked from the New File(s) dialog box. The following table describes the available wizards, shows their icons, and describes the types of files generated by each wizard (note that you can choose from existing files rather than generate new ones):

Icon
Wizard
Description
Generated Files

Data Model
Creates a data model.

Input
Creates a generic input form and a servlet to handle the input.

Results
Creates a generic servlet and JSP

Database Forms
Enables the user to perform interactions with a relational database and generate complex reports and forms.

Login
Creates login functionality, optionally with password verification.

Query
Creates a SQL statement.

HTML Page
Creates an HTML page.

Java-Server Page
Creates a JavaServer page.

Servlet
Creates a servlet.


Java File
Creates a java class.

Base Servlet
Creates a base servlet.

App-Resource
Creates an AppResource.

Session
Bean

Creates a session bean.

Entity
Bean

Creates an entity bean.

Note. In all of these wizards, click Next to move on to the next step, or click Back to return to a previous step.


Using the Data Model Wizard
The data model wizard allows you to specify the database tables and relationships between them. You must create a data model before you can create a query or form. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Data model definition
filename.kdm

To launch the Data Model wizard, select New File(s) from the Project menu. Select Data Model and click Add. The Insert Tables dialog appears, which allows you to use an existing connection or create a new one. Previously established connections are defined as a *.props file in NAS's Connections folder. If you create a new connection, you must specify the driver, data source, username, password, and, optionally, a database name, for your connection.

After choosing or creating the connection, the Add Tables dialog appears, allowing you to specify the tables you want to include in your data model. Once the tables have been identified, you complete the data model by defining relationships between fields in the tables. Netscape Application Builder displays a visual representation of the tables from which you select a field from one table and drag it to its related field in another table. Be default, each relationship you create is one-to-many from the dragged field to the destination field. You can change the kind of relationship by selecting the line between the fields and modifying the Relationship property in the Properties editor.

When you finish defining relationships and close the window, Netscape Application Builder prompts you for the file name in which to save your data model.


Using the Input Wizard

The Input wizard creates a generic input form and a servlet to handle the input. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
HTML page with a data input form
filename.html
Servlet to process the form
Calledfilename.java
NTV file
Calledfilename.ntv
Empty HTML template to display the results
Calledfilename.jsp
Insert query to store data to a data source (optional)
Calledfilename.gxq

The generated HTML form consists of a basic form structure containing the input parameters you specify in the wizard. The form's SUBMIT button submits the form to the generated servlet, which processes the input and merges results with the generated JSP.

  1. To launch the Input wizard, select New File(s) from the Project menu.
  2. Select Input and click Add.
  3. Enter a base filename and location for the generated files.
  4. Choose how you would like to process the input information, depending on how the input parameters are processed.
Handle Information with Custom Code

If you choose to handle the input with custom code, the wizard prompts you for the input values that you want to make available to your servlet. Choosing to use custom code causes the wizard not to generate a query file.

Store to a Database Table

To enable the input to be inserted directly into a database using a new INSERT query, choose "Store to a database table" and click Next.

Perform the following steps to store the input to a database:

  1. First, select a data model on the Specify Data Model dialog box. If you have not yet created a data model for this project, or if your data model is not appropriate for this input, select Create a New Data Model to exit the Input wizard and create a new data model (see Creating a Data Model).
  2. In the Specify Data Connection dialog box, choose "Use an existing connection" if you have already set up a database connection. Otherwise, choose "Create a new connection" and click Next. Choose a database driver, a data source, and a user name and password.
  3. In the Select Input Fields dialog box, choose a table from your data model. The fields in the table appear in the left column. For each table, choose whether the field appears on the form at runtime.
You must edit the generated JSP to display the results.


Using the Results Wizard

The Results wizard creates a generic servlet linked to an empty JavaServer Page (JSP). You can then create presentation logic in the servlet, and edit the JSP to show the results of the servlet's processes. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Empty JavaServer Page
filename.html
Generic servlet linked to the JSP
filename.java
NTV file
filename.ntv

The generated servlet is a generic stub you can use to develop a piece of your application. The results of the servlet activities merge with the generated JSP to produce an HTML page at runtime.

To launch the Results wizard, select New File(s) from the Project menu. Select Results and click Add. The Specify Servlet Name and Location dialog box appears. Enter a base filename and location for the generated files.

Specify input parameters for the servlet. If you already have an HTML input page, you can read input parameters from it automatically. Alternatively, you can enter the parameters by hand using the Specify Input dialog box, shown here:

To read parameters from an existing page, select the page from the drop-down box at the bottom of the Specify Input dialog box, or click Browse to search the filesystem for the page. To specify parameters by hand, enter the name and select the appropriate settings for other properties.


Using the Database Forms Wizard

The Database Forms wizard enables you to set up interactions with a relational database and generate complex reports. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
HTML page with a data input form and optional search functionality
filename_Search.html
Optional query file to retrieve data from database
filename.gxq
Servlets to process the query
filename.java
JavaServer Page to display the results
filename.jsp
Servlets to process the query (optional)
filenameDetail.java
JavaServer Page to display the results (optional)
filenameDetail.jsp

The generated servlet processes form or search data from generated HTML files, uses the data model and query file to retrieve data from a relational database, and merges this data with the generated JSP to display the results as a static report or an editable form.

To launch the Database Forms wizard, select New File(s) from the Project menu. Select Database Forms and click Add. The Specify Servlet Name and Location dialog box appears. Enter a base filename and location for the generated files.

Choose how you would like to define the data used on your forms and reports. You can choose Use an Existing Query File, or choose Use a Data Model to create a new query file.

Use an Existing Query File

Choose a query file from the drop-down list, or browse for one. When you find the file you want to use, the Select a Query dialog box prompts you to choose a single query from the queries in the file.

If you choose a select query, the Select Records Display dialog box prompts you to choose whether records should be displayed as a single record, in which only the first row of data found by the query appears in the final output, or multiple records, where all rows of data appear in the final output.

Use a Data Model

If you choose to create the details of your query from scratch, use the Select Pages to Create dialog box to choose what kind of output pages you want to produce.

A master record is the primary target of a query. A detail record is the result of a secondary query, based on the master record. Combinations of master and detail queries are shown. If a set of pages can be produced, they are linked together with standard VCR-type navigation tools (first record, next record, previous record, and last record).

The types of output pages are described below:

Type of Pages
Example
Single record master
An account
Multiple record master
A list of accounts
Single record master and multiple record detail (single page)
A single accounts and a list of transactions on that account
Single record master and multiple record detail (multiple, linked pages)
A single account and a list of all transactions on that account
Multiple record master and single record detail
A list of accounts, and a detailed view on each account
Multiple record master and multiple record detail
A list of accounts, and a list of all
transactions on each account

Additionally, you can check the "Create a search page" checkbox to generate a form that enables users to search for certain records by specifying search criteria.

Specify a data model (or exit the wizard to create one). On the Specify Data Connection dialog box, choose "Use an existing connection" if you have already set up a database connection. Otherwise, choose "Create a new connection" and click Next. You are prompted to choose a database driver, a data source, and a user name and password.

Depending on the type of output you want to produce, you are prompted for display field information, first for the master query and next for the detail query. Complex pages are shown with either a master section (for single-page output) or a master page (for multiple-page output).

In each case, you must provide the following information if it is relevant to your selected output scenario:

Dialog Box
Information to Provide
Select Display Fields
Choose the fields you want to display on the page or section by selecting a table and one or more fields, and moving the fields into or out of the "Fields to display" column using the left and right arrow buttons between columns. Doubled arrows move all fields at once. You can use the up and down arrows on the right to adjust the order of the fields. You can use fields from multiple tables.
Select Table Format
Choose which fields are editable if you are creating a form as output, or choose "Display-only fields" to create a database report.
Select Sort Fields
Choose which field(s) to use as a sort key when displaying
multiple records. This dialog box functions similarly to the Select Display Fields dialog box described above, with the addition of buttons you can use to specify the field to be sorted ascending or descending.
Specify Primary Key(s)
Choose a field that guarantees the uniqueness of a row in
the query. Note that database-controlled fields (such as auto-increment fields) usually cannot be updated by a normal database transaction; in this case, be sure to specify any auto-increment fields as noneditable when prompted.
Select Drilldown Field
Choose a field to use as a hypertext link from the master page to the detail page by selecting a field from the "Display field" drop-down box. Then specify columns to join, and the operator for joining them. The master fields automatically become links to the appropriate detail pages.
Select Columns for Search Page
If you chose to create a search page, choose which fields in
the query should appear on the search page, and what kind of search should be possible.


Using the Login Wizard

The Login wizard enables you to create login functionality, optionally with password verification. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Static HTML page with a data input form
filename.html
Optional query file to retrieve data from database if login is authenticated by database table
Calledfilename.gxq
Servlet to process the login
Calledfilename.java
NTV file
Calledfilename.ntv
JavaServer Page to display the results of a successful login
Calledfilename.jsp

To launch the Login wizard, select New File(s) from the Project menu. Select Login and click Add. The Specify Page Name and Location dialog box appears. Enter a base filename and location for the generated files.

Specify input parameters in the Specify Input dialog box. These parameters appear as text input boxes in a form on your login page. The servlet uses these parameters to verify the login. Default input parameters are Username and Password.

For each parameter, enter or choose the following information:

Parameter Attribute
Description
Name
Parameter name
HTML Type
Type of entry box for this parameter. Valid types include the following:
Default Value
The value submitted with the form if the user enters nothing.
Validation
Optional validation for Text, TextArea, or Password fields (see Validating Data Entered on a Form)
Required
Check this box if this parameter is required.

The Select Login Authentication dialog box prompts you to choose a method for verifying that the provided parameters constitute a valid login. The available options, Database Table, LDAP Server, and Custom, are described in the following sections.

Database Table

To authenticate your login against a database, first choose a data model, or exit the wizard and create one if needed. Create a database connection by providing a database driver, a data source, and a user name and password.

On the Specify Database Login Information dialog box, choose a database table that contains login fields, and then match your input parameters with database fields.

You can save any of the fields in the table as session variables by checking the Save to Session checkbox for that field on the Specify Query Outputs to Save to Session dialog box.

LDAP Server

The Specify LDAP Server Information dialog box prompts you for information to enable a connection to the LDAP server to authenticate the login. Specify the same server name, port, organization and country as you did when you installed your directory server. Use the drop down list to choose the source of the values for the name and password.

Custom

For Custom authentication, you must provide code in the generated servlets to authenticate your users.


Using the Query Wizard

The Query wizard creates a SQL query from the tables in your data model. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Query file
name.gxq

To launch the Query wizard, select New File(s) from the Project menu. Select Query and click Add. The Specify Base Name and Location dialog box appears. Enter the name and location for the generated file. The Specify Data Model dialog appears next; you can select a data model from within the current project or browse for a data model in another project.

You are then prompted for the kind of query, which is either Select, Insert, Update, or Delete. A dialog that matches the kind of query appears. These dialogs are explained in "Creating Queries" on page 275.


Using the HTML Page Wizard

The HTML Page wizard creates an empty static HTML page. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
HTML file
name.html

To launch the HTML Page wizard, select New File(s) from the Project menu. Select HTML Page and click Add. The Specify Base Name and Location dialog box appears. Enter the name and location for the generated file. Netscape Application Builder creates a minimal HTML page, which sets the title and colors, in the project's HTML Pages folder and allows you to start editing the file.


Using the JSP Wizard

The JSP wizard creates an empty JSP file that is used to display dynamic data-bound HTML output. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
JavaServer page file
name.jsp

To launch the JSP wizard, select New File(s) from the Project menu. Select JSP and click Add. The Specify Base Name and Location dialog box appears. Enter the name and location for the generated file. Netscape Application Builder creates a minimal JavaServer page, which sets the title and colors, in the project's Java Server Pages folder and allows you to start editing the file.


Using the Servlet Wizard

The Servlet wizard creates a Java code file that you can use to define your business logic. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Servlet file
name.java
NTV file
name.ntv

To launch the Servlet wizard, select New File(s) from the Project menu. Select Servlet and click Add. The Specify Base Name and Location dialog box appears. Enter the name and location for the generated file as well as the servlet's superclass. Netscape Application Builder creates a Java code file, which defines the package, imports, class, and the class's defaultAction() or service() method, in the project's Java folder and allows you to start editing the file. If you are using Netscape Application Builder's extended services, the file contains the defaultAction() method; otherwise, it contains the service() method. For more information, see "Standard Servlets" on page 309.

Note. The NTV file contains properties, which you modify from Netscape Application Builder's Properties window. Do not modify the NTV file directly.


Using the Java File Wizard

The Java File wizard creates an empty Java code file that you can use to implement non-servlet code, such as helper or utility classes. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Java code file
name.java

To launch the Java Class wizard, select New File(s) from the Project menu. Select Java Class and click Add. The file is given the title Untitlednn.java. You are prompted to change the name of the file when you close it after you modify the contents.


Using the Base Servlet Wizard

The Base Servlet wizard creates a subclass of a servlet class that you can use to define RowSet objects or methods that you want to access from your servlets. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
Base servlet Java file
name.java

To launch the Base Servlet wizard, select New File(s) from the Project menu. Select Base Servlet and click Add. The Specify Base Name and Location dialog box appears. Enter the name and location for the generated file as well as your base servlet's superclass. Netscape Application Builder creates a Java code file, which defines the package, imports, class, and the class's service(), includeDefaultJSP(),defaultAction(), and error() methods, in the project's Java folder and allows you to start editing the file. It also contains the getEJBHomebyJNDIName() method, which contains NAS-specific code that allows you to retrieve an instance of an EJB.


Using the AppResource Wizard

The AppResource wizard creates a wrapper class in which you can include getter and setter methods for the strings in your HttpSession object, allowing you to provide access to session values from a JavaBean. You can access these values by calling the HttpServletRequest2 class's getHttpSessionBean() method. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
AppResource file
name.java
NTV file
appInfo.ntv

To launch the AppResource wizard, select New File(s) from the Project menu. Select AppResource and click Add. The Specify Base Name and Location dialog box appears. Enter the name and location for the generated file. Netscape Application Builder creates a Java code file, which defines the package, imports, class, and constructor, in the project's Java folder and allows you to start editing the file.

Note. The NTV file contains properties, which you modify from Netscape Application Builder's Properties window. Do not modify the NTV file directly.


Using the Session Bean Wizard

The session bean wizard creates the Java files and a .properties file needed to implement a session bean. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
EJB remote interface source file
Ihomename.java
EJB enterprise bean source file
homenameBean.java
EJB home interface source file
IhomenameHome.java
EJB properties file
homename.properties

You place methods in the enterprise bean source file to implement application-specific behavior in an EJB. The source files generated by the EJB wizard compile but have no application-specific behavior. You will have to add code to all three source files to create useful behavior; see http://java.sun.com:8081/ejb/docs.html for more information.

To launch the Session Bean wizard, select New and then Session Bean from the File menu. The Specify Base Name and Location dialog box appears. Enter the string thay you want to use to construct the EJB's home name for JNDI registration as well as to create names for the NAB-generated Java and .properties files. You can change the directory if you wish. By default, it is the combination of the NAS installation directory, the relative pathname of the server's application root, and one of the following:

The package part of the directory name, which is the part after the application root, is used as the package name for NAB-generated source files. Consider the following example, in which NAS is installed a C:\Netscape\Server4, the relative pathname for the application root is nas\Apps, the package is myBeans.Credit, and the base name is CreditCheck. The generated path and file names would be as follows:

Generated File
File Name
EJB remote interface source file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
ICreditCheck.java

EJB enterprise bean source file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
ICreditCheckBean.java

EJB home interface source file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
ICreditCheckHome.java

EJB properties file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
CreditCheck.properties

In this example, the JNDI name is myBeans/Credit/CreditCheck.

You can change the names of the generated files in the next dialog box. The next dialog box also allows you to specify the following bean properties and control descriptors:

Property or Control Descriptor
Values
Bean class name
any valid class name
Bean home interface name
any valid class name
Bean remote interface name
any valid class name
Isolation level
One of the following levels:
Run mode
One of the following modes:
Transaction attribute
One of the following attributes:

The next dialog box allows you to specify whether the bean is stateless or stateful. If the bean is stateful, you can specify a timeout value for the bean, which is 10,000 seconds by default.


Using the Entity Bean Wizard

The entity bean wizard creates the Java files and a .properties file needed to implement an entity bean. The following files are generated, with filenames based on the name you specify:

Generated File
File Name
EJB remote interface source file
Ihomename.java
EJB enterprise bean source file
homenameBean.java
EJB home interface source file
IhomenameHome.java
EJB properties file
homename.properties

You place methods in the enterprise bean source file to implement application-specific behavior in an EJB. The source files generated by the EJB wizard compile but have no application-specific behavior. You will have to add code to all three source files to create useful behavior; see http://java.sun.com:8081/ejb/docs.html for more information.

To launch the Entity Bean wizard, select New and then Entity Bean from the File menu. The Specify Base Name and Location dialog box appears. Enter the string thay you want to use to construct the EJB's home name for JNDI registration as well as to create names for the NAB-generated Java and .properties files. You can change the directory if you wish. By default, it is the combination of the NAS installation directory, the relative pathname of the server's application root, and one of the following:

The package part of the directory name, which is the part after the application root, is used as the package name for NAB-generated source files. Consider the following example, in which NAS is installed a C:\Netscape\Server4, the relative pathname for the application root is nas\Apps, the package is myBeans.Credit, and the base name is CreditCheck. The generated path and file names would be as follows:

Generated File
File Name
EJB remote interface source file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
ICreditCheck.java

EJB enterprise bean source file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
ICreditCheckBean.java

EJB home interface source file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
ICreditCheckHome.java

EJB properties file
C:\Netscape\Server4\nas\Apps\
myBeans\ Credit\CreditCheck\
CreditCheck.properties

In this example, the JNDI name is myBeans/Credit/CreditCheck.

You can change the names of the generated files in the next dialog box. The next dialog box also allows you to specify the following bean properties and control descriptors:

Property or Control Descriptor
Values
Bean class name
any valid class name
Bean home interface name
any valid class name
Bean remote interface name
any valid class name
Isolation level
One of the following levels:
Run mode
One of the following modes:
Transaction attribute
One of the following attributes:

 

© Copyright 1999 Netscape Communications Corp.