Creating JSP Browse and Edit Forms

This topic describes the steps involved in creating the model, controller, and view layers of a databound Struts application that allows users to:

This topic contains the following sections:

Overview

When the application is complete, running it from the Page Flow Diagram first displays the browse web page, which looks like this:

Browse web page

The edit web page looks like this:

Edit web page

The following diagram shows a simple view of the steps you need to take in the model, controller, and view layers to create this page flow:

Scenario steps in Model, View, and Controller layers

Following is a more detailed discussion of the high-level steps you need to take in the Model, Controller, and View layers to create this page flow.

Model Layer

Controller Layer (Design Time)

View Layer

Controller Layer (Runtime)

Note: Although it is possible to create the entire controller layer in the Page Flow Diagram before you create your JSP pages in the view layer, most developers create a data page and its associated web page before they build the rest of the page flow. The structure of the following sections reflects this iterative approach.

Creating the Browse Page Functionality

This section describes how you create the data page and web pages used to display the browse page functionality for this page flow.

To create the browse data page and associated JSP page:

  1. Open the Struts Page Flow Diagram.

  2. Add a Data Page element to the Page Flow Diagram. Rename the data page /browsePage.

    This step creates the following entry in the struts-config.xml file:

    <form-beans>
     <form-bean name="DataForm"
      type="oracle.adf.controller.struts.forms.BindingContainerActionForm"/>
     </form-beans>
    <action-mappings>
     <action path="/browsePage" className="oracle.adf.controller.struts.actions.DataActionMapping"
      type="oracle.adf.controller.struts.actions.DataForwardAction"
       name="DataForm" parameter="unknown"/>
    </action-mappings>
    <message-resources parameter="view.ApplicationResources"/></action>

    When you add a data page, JDeveloper uses Oracle ADF subclasses for the action className and type attributes. In addition, it creates a form bean with the name DataForm. The DataForm form bean dynamically makes the attributes for any binding container available to forms in the application web pages. For more information about action mapping using the Oracle ADF action subclasses, see About the Page Flow in Databound Struts Applications.

  3. Double-click the /browsePage icon and click OK in the Select or Create Page dialog box to create a JSP page named browsePage.jsp. Leave the Edit this page now? checkbox selected when you do this.

    JDeveloper creates the browsePage.jsp file and opens the page in the Visual Editor.

  4. In the Data Control Palette, select DepartmentsView1. Select Read-Only Form from the Drag and drop as list and drag DepartmentsView1 to the empty JSP page:

    Described in text

    The Data Control Palette displays the business services available for the page. In this step, you are adding a read-only form that uses a view object, DepartmentsView1, to display the data from the Departments table in the HR database. The user navigates through this table to display the employees for each department in the detail table created in step 4.

    When you add the first databound form to the web page, JDeveloper creates two Oracle ADF project files, DataBindings.cpx and browsePageModelUI.xml, in the view folder. DataBindings.cpx defines the binding container for the application as a whole. browsePageModelUI.xml is the model reference, which defines the data controls used by the individual web page.

    At this point, JDeveloper also updates the struts-config.xml file to define the model reference in the associated <action> element by adding a <set-property> element in the action mapping:

    <set-property property="modelReference" value="browsePageUIModel"/>

    For more information about the Oracle ADF project files, see About the Oracle ADF Project Files. For more information about the Data Control Palette, see Inserting UI Components Using the Data Control Palette.

  5. In the Data Control Palette, select DepartmentsView1. Select Navigation Buttons from the Drag and drop as list and drag DepartmentsView1 to the bottom of the existing form. In the Add Form Element confirmation dialog box, select No to include the buttons in the existing form:

    Navigation buttons in form

    These buttons make it possible for the user to navigate among the rows in the Departments form.

  6. In the Data Control Palette, select EmployeesView3 under the DepartmentsView1 node. Select Read-Only Table from the Drag and drop as list and drag EmployeesView3 to be a separate form below the first form.

    EmployeesView3 is a view object that displays a list of employees by department.

  7. Add a column which will contain a link to pass the key for the selected row to the edit page. Click inside the first column of the table, right-click and choose the Tools | Table | Insert Column menu item.

  8. Next, create the link that will take the user to the edit page.

    Select the setCurrentRowWithKey operation under the EmployeesView3 node and choose Find Row Link from the dropdown list. Your palette selections should look similar to this:

    Data Control Palette with operations

    Add the link to the first column in the second row (again dragging the selection from the top portion of the Data Control Palette into the field below the forEach statement).

    The following code segment shows what the operation looks like in the code view of the JSP page:


    <a href="browsePage.do?event=setCurrentRowWithKey&Arg0=<c:out value='${Row.rowKeyStr}' />">Edit</a>

    Note: As shown in the code in this example, when you add a regular <a href> tag to point to an action, you do not include a preceding slash (/).

    For more information about the operations available in the model layer, see About Supported Data Collection Operations in Oracle ADF.

  9. Edit the link by right-clicking on the link and choosing Edit Tag. Change the link text from Select to Edit.

    The design view of your JSP page should look like this (not shown in its entirety):

    Described in text

  10. In the Data Control Palette, select the Commit icon in the top level Operations node. Choose Button with Form from the Drag and drop as list and drag the Commit data control to be a button below the second table.

    The browse page for the application is now complete.

Creating the Edit Page Functionality

This section describes how you create the data page and web pages used to display the edit functionality for this page flow.

To create the Edit Form Page:

  1. In the Component Palette, click the Data Page element and drag it to the Page Flow Diagram. Name the data page /editEmpRowPage.

    When you add this data page, JDeveloper creates an entry similar to the previous one in the <action-mappings> section of the struts-config.xml file.

  2. Double-click the /editEmpRowPage icon and click OK in the Select or Create Page dialog box to create a JSP page named editEmpRowPage.jsp . Leave the Edit this page now? checkbox selected when you do this.

    The design time creates the editEmpRowPage.jsp file and opens the page in the Visual Editor.

  3. In the Data Control Palette, select the EmployeesView3 node. Select Input Form in the Drag and drop as list and drag EmployeesView3 to the empty JSP page.

    The input form contains all of the data bindings and link information needed for the user to update row data and submit it. The edit employee form page is now complete.

Creating the Action Forwards

This section describes how to use the Page Flow Diagram to create the forward transitions needed by the page flow.

To create the forward transitions:

  1. Click on the forward icon in the Data Control Palette and draw a forward transition from /browsePage to /editEmpRowPage. Name the transition setCurrentRowWithKey.

    The page flow looks like this:

    Described in text

    The forward name corresponds to the operation the application performs, setCurrentRowWithKey(), when the user clicks the Edit link in the second table. You created this link when you created the browse page for the scenario. When you add this forward, JDeveloper adds the <forward> element to the action mapping for the first data page:

    <forward name="setCurrentRowWithKey" path="/editEmpRowPage.do"/>

    For more information about associating an operation with an action forward, see Working with Named Events in Oracle ADF.

  2. Draw a forward from /editEmpRowPage to /browsePage. Name the transition Submit.

    When you add this forward, JDeveloper adds a <forward> element to the action mapping of the second data page.

Running the Application

You are ready to run the databound browse and edit pages from the browsePage data page you created in the Struts Page Flow Diagram.

To run the application:

  1. Return to the Page Flow Diagram by clicking on the struts-config.xml tab above the Visual Editor.

    Described in text

  2. Right-click on the /browsePage icon and choose Run.

    When the edit page displays in the browser, click an Edit link for any row. You can edit a field and click Submit to return to the browse page.

    Note: If the update of data is unsuccessful, the application redisplays the input page.

  3. When you return to the Browse page after editing a record, the Commit button is no longer faded and you can click it to commit the update transaction.

About the Databound Web Application Page Flow
About the Page Flow in Struts Applications
About the Oracle ADF Bindings
About the Oracle ADF Data Binding Properties
About Oracle ADF Data Controls

 

Copyright © 1997, 2004, Oracle. All rights reserved.