Use Web Page Wizards

Creating JavaServer Pages (JSP) files

You can create and edit a JSP file in Page Designer by adding your own text and images using JavaScript, HTML, or JSP tagging, including Java source code inside of scriptlet tags. You can also create JSP files hat are based on Struts or JavaServer faces architecture.

To create a new JSP file, do the following:

  1. To launch the New JSP File wizard, select File > New > JSP File.

  2. Select the appropriate container for the file from the list of project folders (and subfolders).

    The folder that you choose should be under the Web Content folder of the Web project. If a JSP file is not under this folder, then it will not be included in the WAR file that is deployed to the server. In addition, link validation will not encompass files that are not under the Web content folder.

  3. Type a file name into the appropriate field.

  4. Ensure that the appropriate option is displayed in the Markup Language drop-down list.

    In addition, if you select the Create as JSP Fragment check box, this file will be created as a fragment that can be added to another JSP file. Other JSP files can include JSP fragments using a JSP include directive. Creating a fragment causes the resulting file to end in a .jspf or .jsf extension. You will not be prompted for DOCTYPE information, because a fragment cannot stand alone as a Web page, and it would invalidate any JSP file that included it.

    Also, depending which markup language you select, you can select the Use XML Style Syntax option to create a JSP file that adheres to XML style tagging.

  5. You have several options for proceeding:

    • If you want to accept the defaults associated with a new JSP file, leave Model as None.

    • If you want to create a JSP file that uses Struts architecture, select Struts JSP in the Model field.

    New JSP Wizard

  6. Click Finish to create the file, or Next to provide additional information.

  7. Optionally add tag libraries from a variety of sources by clicking the Add Tag Library button to locate a TLD file or a JAR file that contains a TLD file. Tag library Universal Resource Identifier (URIs) can be located in one of the following places:

    • Defined in the web.xml file

    • Within a JAR file located in the project lib directory that contains /META-INF/taglib.tld

    • Within a JAR file external to the project

    • In a "loose" TLD anywhere in the project

    In the Select a Tag Library dialog, either select one of the available tag libraries, or click the Import button to locate and add a tag library to the list, and then select it. The dialog will automatically populate the informational fields that describe the tag library and its contents. You must specify a Prefix value. Click OK to add the tag library:

    Select a tag library

  8. As you add tag libraries, the Available Custom Tags window displays the the declaration of the tag along with the tag library directive. If the selected TLD file that hasn't been registered in the web.xml file, it will be added automatically.

    Available Custom Tags

  9. Click Next to supply page directive information for the JSP file. The imported class and package information are editable. Use the checkboxes to define any additional attributes, including a buffer size, an associated error page, and other modal options.

    Page directive information

  10. Click Next to supply encoding, DOCTYPE and style sheet information.

  11. Select the appropriate encoding value to add to the JSP's declaration from the Encoding list button. The default is the value set in the JSP Files preferences page, which is accessed by selecting Window > Preferences, and then expanding the Web and XML Files preferences.

  12. Ensure that the proper content type is selected in the Content Type drop-down list.

  13. Select the HTML Document Type that you wish to associate with the JSP file. Depending on which Document Type that you select using the list button, the corresponding Public ID, and, if appropriate, System ID will be displayed.

  14. Optionally, specify one or more cascading style sheet (CSS) files to to be referenced by the new JSP file. Typically, CSS files are located in the /theme folder under the Web Content folder.

    Document Type

  15. Click Next to select specific method stubs and add deployment information to the Web project's web.xml file.

    Select any appropriate method stubs to be created in the servlet that is deployed for this JSP file.

    If you select the Add to web.xml check box, the JSP file, along with its display name, and any URL mappings and initialization parameters associated with the JSP file will be automatically included in the Web project deployment descriptor file. Note that the File Name value provided in the previous page of the wizard is automatically mapped to the Servlet Name value on this page, as well the URL Pattern mappings. These mappings are not updated if you change the original value in the File Name field.

    URL Pattern

  16. Click Finish to create the file in the project that you have selected. The file will open in an HTML editor. The default is Page Designer, in the Design page.

Creating Web pages from Java beans

The Create JavaBeans Web Pages wizard supports the following activity models:

Follow these steps to create Web pages from Java beans:

  1. To launch the Java Bean Web Pages wizard, select File > New > Other. Then select the Web option, Java bean Web Pages, and then the Next button.

  2. On the initial wizard page, use Browse to specify the location into which the generated Web pages will be placed, as well as where all servlets will be mapped. The Java package name specifies where all Java source code will be placed. A default package is assumed if you do not designate a package name.

  3. The View Bean model is the only model type currently available from the drop-down list. This model uses view helpers, which are Java-wrapper classes that manage all database interaction.

  4. You also have the option to create and generate an Input form, a JSP Results page, a Controller Servlet, or a View Bean. In the course of completing the wizard, you will have an opportunity to customize the content and layout of these generated objects. The File Description area provides information about each object that you select.

    Options

  5. Click Next.

  6. Use Browse to locate the bean that will act as the model for your generated Web pages, or type the class name in the Bean field. For purposes of the wizard, any Java class that has a public constructor is considered to be a bean.

    Note: If you use the Browse button, when you click OK in the Choose Java bean dialog, the bean is automatically introspected.

    There are three potential locations for the bean:

    • In the Java Source folder of your Web project.

    • In a .jar file containing included in the Java Build path of your Web project.

    • In the Java Build path of your Web project.

  7. If you typed the bean name, click the Introspect button to initiate bean introspection. The wizard supports complex data types, including user-defined classes, arrays of Objects and Primitives, Collections, Iterators, Enumerations, Maps, and ResultSets. The introspection is performed on the entire definition hierarchy; however, you will be able to select the level of granularity used in the generated pages from a hierarchy tree of the complex type.

  8. Using the check boxes or the All or None button, select the bean methods to be executed by the servlet. The wizard should make available the public void methods() { } that have primitive type parameters from your Java bean. The wizard also provides additional public methods inherited from any of the superclasses in the bean's hierarchy.

    Select methods

  9. Click Next.

  10. In the View Bean Data Page, use the Add button to locate and add a style sheet from your workspace. To use an error page, click the check box and use the Browse button to locate the error page.

    Style Sheets allow you to define colors, fonts and many other attributes of your HTML tagging. The error page enables you to specify a URL that is forwarded to a user's browser if an error is encountered while executing one of the generated resources.

  11. Select the Request or Session radio button to identify the model type. Storing the results in a session will allow the data to be used in multiple pages for the duration of the session. Storing the results in a request will allow access to the data only for the duration of the request; the result set is destroyed after the request is processed, freeing up memory on the server. The default is Request.

  12. Optionally, you can include or remove processing layers from the model used to generate Web pages.

    A Front Controller is a servlet that serves as the single entry point for all requests to a Web application region. A controller provides a single point to perform all authentication, logging, debugging, and to all subsequent views, including the input, master results, and details results views. You can choose to automatically create a new controller, reuse an existing controller, or not use a controller at all [default]. If you choose not to use a controller, that functional layer of processing is not performed.

    View Beans are wrappers that allow you to have more control over how data is displayed when it is rendered in generated Web pages. If you deselect this option, the wizard accesses data using the underlying beans directly.

    Select options

  13. Click Next

  14. Design the input form by specifying the page properties and the bean properties and method parameters (fields) that the generated Web page will expose to user input. This page will show you the public properties of the bean, as well as any parameters that must be specified for the methods selected on the previous page. Expand the tree to view more of the complex type hierarchy if you want add greater granularity to the form. The scrolling panel on the right side of this page approximates the look and layout of the resulting page.

    You can also use the All or None button to select or deselect the entire list (although parameters lower in the hierarchy are not selected). Click the up and down arrow buttons to reorder the columns in the input page.

  15. Select and update, as needed, values in the properties table.

    Properties

  16. Click Next.

  17. Design the result form by specifying the page properties and the bean properties (fields) that the generated Web page will display as output to the user. Expand the tree to view more of the complex type hierarchy if you want add greater granularity to the form. The wizard should only make available the public void getMethods() { } from your Java bean.

    You can also use the All or None button to select or deselect the entire list (although parameters lower in the hierarchy are not selected). Click the up and down arrow buttons to reorder the columns in the input page.

  18. Select and update any of the following properties:

    Page - Page properties include Page Title, Background Color, Title Color, and Field Color.

    Field - Field properties include ID, Label, Initial Value, Field Type, Size, Max Length, and Layout Style. Note that the Size property addresses the physical dimensions of the field, and the Max Length is a specification of the maximum number of characters or string length allowed.

    Properties

  19. Click Next

  20. Provide a common Prefix for the pages that are generated from the specified beans. Note that the list of generated pages and resources will reflect any changes to the prefix as you type in the Prefix field.

    Prefix

  21. Click Finish to generate the Web pages.

Creating Web pages from SQL statements

The Database Web Pages wizard uses servlet technology to generate Web pages from SQL statements. After providing some general storage and Web page creation parameters, you will select a database model or establish a connection to a database to import a model. Next, you will build a new statement or use an existing statement as a basis for generating Web pages. You can create an input page that collects information to filter the SQL statement, and design the result and detail pages that will format and display the resulting filtered statements to users.

Follow these steps to create Web pages from an SQL statement:

  1. To launch the Database Web Pages wizard, select File > New > Other. Then select the Web option, Database Web Pages, and then the Next button.

  2. Specify the location into which the generated JSP and HTML files will be placed, as well as where all servlets will be mapped. You should select the Web Content folder, or one of the folders under Web Content. The Java package field specifies where all Java source code will be placed. A default package is assumed if you do not designate a package name.

  3. Select one of the SQL statement types from the SQL Statement Type list box.

  4. Select one of the generation models from the Models list box. The Description area provides information about the generation model that you have selected. Based on the statement type and generation model combination, the Files list box lists the pages that will be generated. If you click on a file, a short description is displayed in the File Description box.

  5. You also have the option to create and generate an Input Form, the Select Master View or just a Select Details View, or Front Controller. In the course of completing the wizard, you will have an opportunity to customize the statement content and layout of these forms. The File Description area provides information about each form that you select.

    Database Web Pages

  6. Click Next.

  7. Choose how to create the SQL statement. If you already have an SQL statement written, from the Select an existing statement saved in your workspace page, you can browse to locate a statement that exists in a workbench project. Click Next.

    Choose SQL statement

  8. Choose whether to use a data source connection or a driver manager connection in the Runtime Connection Page. A data source connection name should be the JNDI name defined in the server configuration.

    A data source is the preferred database connection type for a Web application. A data source is defined in a Web server. Usually, it is a pooled connection, so that the server makes a pool of connections to the database on startup. Each time a JSP file requires a database connection, the server provides one of its pooled connections, which minimizes the connection overhead for the JSP file. When the JSP is done executing, it releases the database connection back to the pool.

    For a driver manager connection, the JSP file requires a new connection to the database on each execution. Supply the driver name and associated URL.

    Supply the User ID and Password, along with a verification of the password, necessary to access the target database. If this is a new connection, the User ID and Password specified in the Database Connection page are reflected here. If you used an existing database model or an existing SQL statement, these are the values originally used to load the existing database model. The User ID and Password will be added to the web.xml file as an initialization parameter of the servlets associated with the Master View and Details View result pages.

    Runtime Connection Page

  9. Click Next.

  10. In the Controller Page, select the check box and use the Browse button to associate a style sheet or error page from the current project with the generated Web pages.

    Style Sheets allow you to define colors, fonts and many other attributes of your HTML tagging. The error page enables you specify a URL that is forwarded to a user's browser if an error is encountered while executing one of the generated resources.

  11. Select the Request or Session radio button to identify the model type. Storing the results in a session will allow the data to be used in multiple pages for the duration of the session. Storing the results in a request will allow access to the data only for the duration of the request; the result set is destroyed after the request is processed, freeing up memory on the server. The default is Request.

  12. Optionally, you can include or remove processing layers from the model used to generate Web pages. A Front Controller is a servlet that serves as the single entry point for all requests to a Web application region. A controller provides a single point to perform all authentication, logging, debugging, and to all subsequent views, including the input, master results, and details results views. You can choose to automatically create a new controller, reuse an existing controller, or not use a controller at all [default]. If you choose not to use a controller, that functional layer of processing is not performed.

    Controller

  13. Click Next.

  14. Select and update, as needed, values in the Host variables list and properties table to determine the content, layout, and design attributes of the input form. The scrolling panel on the right side of this page approximates the look and layout of the resulting input page. You can also use the All or None button to select or deselect the entire list. Click the up and down arrow buttons to reorder the columns in the input page.

    At least one column must be specified as a Key Value if you chose to generate a Details form.

    Properties

  15. Click Next.

  16. Select and update, as needed, values in the Result set columns list and properties table to determine the content, layout, and design attributes of the Master View Web page. The scrolling panel on the right side of this page approximates the look and layout of the resulting page. You can also use the All or None button to select or deselect the entire list. Click the up and down arrow buttons to reorder the columns in the result table.

    At least one column must be specified as a Key Value.

    Master View Properties

  17. Click Next.

  18. Select and update, as needed, values in the Host variables list and properties table to determine the content, layout, and design attributes of the Details View Web page. The scrolling panel on the right side of this page approximates the look and layout of the resulting page. You can also use the All or None button to select or deselect the entire list. Click the up and down arrow buttons to reorder the columns in the details table.

    Details View Properties

  19. Click Next.

  20. Provide a common Prefix for the pages that are generated from the statement. Note that the list of generated pages and resources will reflect any changes to the prefix as you type in the Prefix field.

    Prefix

  21. Click Finish to generate the Web pages.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine