This comprehensive workshop shows you how to build applications using
Oracle Application Development Framework (Oracle ADF). The technologies
used in the sample application include Oracle TopLink, Oracle ADF Databinding, Struts, and JavaServer Pages.
In the workshop, you will build a web-based application that provides
for maintenance of customer information. You will start by building the business
services using Toplink. You then build the client portions of the application.
The workshop application is a set of customer maintenance
pages that are used to create new customer records, update existing records,
and delete existing records. During this workshop, you learn how to create these
pages and make them user-friendly and robust enough for a multiuser environment.
Scenario
We need to provide our customer with an application that is
easy to use and understand and that provides useful feedback to the user. The
user needs to be able to edit or delete customer records as well as create new
customer records. Navigation should be easy and intuitive, and feedback needs
to be clear and obvious. For example, when a record is updated, the user needs
a message that indicates success. The same technique should apply to deleting
and creating records as well as handling any errors that may occur. The messages
must be internationalized so that the application can run in multiple languages.
The Customer Maintenance application provides the functions
to maintain customer information. It is built to provide the standard create,
retrieve, update, and delete functions. There are four pages in the application:
The Browse page provides a starting point and a way
to see a list of all customers. The user can select a row and either edit
or delete the row. This page also provides a button that the user can use
to create a new row.
The Edit page provides all of the fields that the
user can modify. This page is also used for creating a new customer row. When
the user creates a new row, the customer ID is not displayed because it is
retrieved from a database sequence. You should have created the sequence as
a prerequisite to this workshop.
The Sure page provides a confirmation opportunity
for the user before a delete is finalized. This page shows the customer row
that a user is about to delete. The user can click either Yes (to delete the
customer row) or Cancel (to abort the delete). In both cases, we display the
correct message and navigate back to the Browse page.
The Errors page displays any error messages that are created during the
delete cycle.
The Customer Maintenance application is based on a rather
simple data model. It is based on a database view of the Customers table. TopLink
is a ramework that makes creating and managing the persistence layer of an application
easy.
Because we use the default behaviors, we can use the Toplink
Wizard to create the business services we need for our application. In the next
few steps, you create the components that you use in the Customer Maintenance
application.
There is a demonstration at the end of this section if you
would like to watch these steps.
Create a new Application workspace
to hold the business model components:
Choose File > New, and then in the General Category,
select Application Workspace.
Change the name of the application to CustomerMaintenance.
Make sure that Web Application [Default] is set as the Application
Template.
Accept the other defaults and click OK to continue.
2.
When you have completed the wizard,
you should have an application named CustomerMaintenance and two projects: Model
and ViewController. You use only the Model project for this part of the workshop.
When
you are finished, the Application Navigator should appear as follows:
Because we are using Toplink as our business services
layer, we use the Toplink Wizard to create all of the components required
for our business model.
To create a set of default components, right-click the Model project
node in the System Navigator and choose New.
2.
In the New Gallery, change the Filter By: option to All Technologies.
Note: The Technology filter is at the top of the New Gallery window.
3.
Expand the Business Tier node and select TopLink.
4.
Select Java Objects from Tables and click
OK to continue.
5.
The first step of this wizard is to establish a connection to your database.
Select the connection name that connects to the OE schema.
Note: If you have not established this connection to the OE schema,
please see the Prerequisites section of this workshop.
6.
For this workshop, we will use the database view that you created in
the prerequisite section. Because we are using a view, you need to click
the Views checkbox to include views in the selection list.
In the next step of the wizard, select the CUSTOMERS_WS_VIEW
, shuttle it to the Selected pane and click next to continue. Accept the
defaults for the rest of the steps in the Wizard.
Click Save after the Wizard is done.
When you are finished, the Application Navigator appear as follows:
7.
Since we are using a database view that doesn't have a primary key, we
need to select one with the TopLink generated object.
Double-click the CustomersWsView.java node in the Application
Navigator. This action opens the Source Editor for the CustomersWsView.java
file.
8.
Click the Mapping tab at the bottom of the Visual Editor.
9.
First, set the Primary Key attribute.
Click the checkbox next to the CUST_ID attribute.
10.
Next, set the descriptor to use a database sequence to populate the CUST_ID
column.
Click the Use Sequencing checkbox
Enter CUSTOMERS_SEQ as the Name value.
Select OE.CUSTOMERS_WS_VIEW as the table value.
Select CUST_ID as the Field value.
11.
In the Applications Navigator, expand the TopLink node and double-click
the TopLinkMappings node to open the TopLinkMappings object in
the Visual Editor.
12.
Click the Use Native Sequencing radio button in the Sequencing
area of the Visual Editor.
The TopLink objects are now ready for deployment descriptors and data
controls. You will create those in the next few steps.
In the previous step, you created the default
Java object for the CUSTOMERS_WS_VIEW view. In this step, you will create the
default deployment descriptor and a default DataControl object. The ADF framework
uses these two components to provide data access to client applications.
1.
To create the default deployment descriptor, expand the TopLink
node in the Application Navigator, right-click TopLink Mappings and choose
Generate toplink-deployment-descriptor.xml from the context menu.
Click OK when the descriptor is created.
2.
The Application Navigator should now look like:
3.
Next, create a default sessions.xml
file. Just as before, right-click Toplink Mapplings and choose New
sessions.xml from the context menu.
4.
The Application Navigator should now look like:
.
5.
Next. add a named session object to the sessions.xml file. You will do
this using the Visual Editor.
Double-click the sessions.xml node in the Application Navigator.
This opens the sessions.xml file in the Visual Editor.
6.
Click Add and add a new session. Accept the default name.
7.
Next, create a DataControl based on the Customers object.
Right-click Customers.java in the Application Navigator and choose
Create Data Control from the context menu.
8.
Change the values in the Deployment Resource wizard to:
Click the Sessions Configuration radio button
Location: sessions.xml(Model.jpr) (from the drop-list)
Sessions: MySessionName(Server) (from the drop-list)
Click OK to continue.
9.
Click Save on the toolbar or choose File | Save All from
the main menu to save your workspace.
The Application Navigator should now look like:
If you would like to watch a demonstration of the previous
tasks, clickhere.
You have now created all of the objects needed for the Business Services
Layer of our application. The next steps will be to create the client
application.
Building an application can be an iterative process. You
have already built the business service layer, so you now create a basic page
flow of the application. After the basic pageflow is complete, you begin developing
page content. As you move through the process, you will probably revisit the
page flow and make additions and changes to make the application more robust.
DataPages are the basic components
of our Web-based Oracle ADF application. The first thing you do is create the
basic framework of the application by creating a DataPage for each of the pages
in the application. The pages are shown at the beginning of this workshop. As
a reminder they are:
Browse page
Edit page
Sure page
Errors
page
You add these DataPages using the Struts diagrammer in JDeveloper.
There is a demonstration at the end of this section if you
would like to watch these steps.
Open the Struts diagram. Right-click the ViewController
project and choose Open Struts Page Flow Diagram from the context
menu.
2.
Now create a DataPage for each of the pages in the application.
browseCustomers
editCustomers
sure
showErrors
To create the DataPages, click the DataPage icon in
the Component palette. The Component palette should be on the right side
of the JDeveloper window.
You can either click the icon or click and drag it to the diagram. If
you click and drag, you have control over where on the diagram the DataPage
is created. Other than that, the two techniques are the same.
When you are done, your diagram should look something like this:
The DataPages you just created are now items in the Struts
configuration, but they do not yet reference pages that display data in
your application. The next step is to create those pages.
3.
In this step, you create and test the browseCustomers page. Double-click
the /browseCustomers DataPage to create a corresponding JSP. You
are prompted for the type of page you want to create. You can select either
a JSP, an HTML page, or a UIX page. For this application, choose /browseCustomers.jsp.
Click OK to continue.
You now have a JSP named browseCustomers.jsp.
The default page that you just created is blank. The next step is to add
some data- aware components.
4.
JDeveloper and Oracle ADF make it easy to add data-aware components to
a page. There are two tabs found at the bottom of the Component Palette,
the Components tab and the Data Control tab. They are the
. The Components tab show all of the nondatabound components, while the
Data Control tab shows all of the ADF-databound components.
Select the Data Controls tab to see the databound components.
Expand the CustomersWsViewDataControl node to see the components
that are available. In this case, there is only one ADF component: readAllCustomer(),
which you created earlier in this workshop.
If you expand the return node, you see all of the individual data
controls that are available for your use.
5.
The browseCustomers page should display multiple customers in a table
layout style. JDeveloper provides drag-and-drop functions to create databound
pages.
Make sure you are in the editor window for the browseCustomers
JSP. If you are not sure, you can double-click the browseCustomers data
page on the Struts Page Flow diagram.
Expand the readAllCustomersWsView() node on the DataControl palette.
Select the return node. Notice the "Drag and Drop As"
list at the bottom of the palette. This list shows the possible styles
you can use for the selected component. Use the Read-Only Table
option for this JSP.
Now that you have selected Read-Only Table, drag the return component
to the browseCustomers.jsp editor window.
The page should now look like:
6.
You have just created an ADF data-aware JSP. To test your new JSP, go
to the Struts PageFlow diagram and right-click the /browseCustomers
data page. Choose Run from the context menu to launch an internal
server that runs your page.
If you run the browseCustomers.jsp from the Application Navigator, the
jsp will run but it will not be data aware or run in the context of the
page flow diagram. You must run the /browseCustomers data page to see
the data aware components.
You page should look like the following:
7.
Now that you have a basic page, add a few navigation buttons to make
it a bit more useful. You add buttons to the page the same way you added
to databound Read Only Table for the return data control.
Expand the return node in the Data Control palette and then the
Operations node. Click the Previous Set component. Select
'Button with Form' as the Drag and Drop as value.
Drag the Previous Set component to the browseCustomers.jsp
editor window, just below the data table.
Select 'Button' as the Drag and Drop as value and drag the Next
Set component to the right of the Previous Set button.
8.
Run the JSP as you did earlier and test the buttons to verify that they
navigate through the list of customers.
If you want to see a demonstration of these steps, click here.
Adding Data Components
to the editCustomers Page
In this task, you add data components to the editCustomers
Page. The only difference in creating the browseCustomers page and this page
is the type of data component that you use. On the browseCustomers page, you
used a read-only table; on this page, you use an Input Form component.
There is a demonstration at the end of this section if you
would like to see what the steps look like.
The first step is to create a JSP that corresponds to the editCustomers
node in the Struts Page Flow diagram. You do that just as you did for
the browseCustomers page: Double-click the editCustomers node and
accept /editCustomers.jsp as the page name.
This opens an editor window for editCustomers.jsp. Click the Design
tab at the bottom of the Visual Editor.
2.
Add an Input Form data component from the Data Component palette as follows:
Select return, select Input Form from the "Drag and
Drop As" list, and drag the return node to the editor window.
3.
Add two buttons to the page. Because this is an edit form, you need to
add a button that accepts and processes any user input as well as a button
that rejects, or cancels, any changes the user makes. Those two buttons
are the Commit and Rollback buttons.
When you added the Input Form component, JDeveloper created a Submit
button for you. Because we are adding our own buttons to manage the submit
function, delete the default Submit button.
Add the two new buttons: Commit and Rollback. Make sure
you are in the editCustomers.jsp window, select the Commit
button from the top-level Operations node, make sure that the "Drag
and Drop As" list is set to Button, and drag the button to
the page within the Form tag which is highlited with a red dotted line.
Repeat this step for the Rollback button.
4.
Rename the buttons to make the page a little more user friendly. The
easiest way to change the label on the button is to double-click the button
and change the Value property.
You can also change that property in the property inspector.
Change the Commit button value to "OK".
Change the Rollback button value to "Cancel".
5.
By default, the code that is created for the buttons includes an expression
that tests to see if the button should be enabled or not. Because this
is an edit form, we want both of the buttons enabled all the time.
Click the Source tab at the bottom of the editor window to edit
the code. To enable the buttons all the time, remove the following code
from the button definitions.
Test the page just as you tested the browseCustomers page earlier. Right-click
the editCustomers on the Struts Page Flow diagram and choose Run
from the context menu.
Notice that there is only one row available and that there is no facility
to scroll through the customer rows. This is deliberate. In the next few
steps, you will connect the browseCustomers page and the editCustomers
page. After they are connected on the page flow, the user starts and finishes
with the browseCustomers page and uses the editCustomers page only for
inserting or editing specific rows.
When you are done, close the browser.
If you want to see a demonstration of these steps, click here.
Connecting
the Pages
You have now created two databound JSPs that
display related data in different ways. The next step is to connect those pages
in a logical way. The browseCustomers page will serve as the starting point for
the users. They will select which row they want to edit from the browseCustomers
page. They can also insert a row staring on that same page. The editCustomers
page is used for editing and inserting rows. We need to create several connections,
called forwards, between these two pages.
In this task, you will add a few buttons to the browseCustomers
page so the user can click either Edit or Create and automatically navigate
to the editCustomers page. You will also add forwards from the editCustomers
page back to the browseCustomers page. Those forwards relate to the user clicking
either the OK or the Cancel buttons.
There are demonstrations in this section if you would like
to see what the steps look like.
JDeveloper and Oracle ADF provide a number of data-aware functions that
make data navigation easy. In the next few steps, you will add some default
behaviors, test them, and then modify them to meet specific needs.
The first thing you will do is add a function that will set the current
row to any row the user clicks. The TopLink model that you created earlier
will synchronize all of the data without any coding on your part.
To add the method that sets the current row:
Open browseCustomers,jsp in the Visual Editor.
Scroll to the right side of the page.
Right-click inside the last column in the table.
Choose Table > Insert Rows Or Columns from the context menu.
Insert two columns after the selection.
These two columns will hold the links, and later the buttons, that you
will add to edit a customer row.
2.
Next, add the setCurrentRowWithKey
method from the data model as a link.
To add this method:
Expand the return node in the Data Control palette.
Expand the Operations node.
Select setCurrentRowWithKey(String).
Select FindRowLink in the "Drag and Drop As" list.
Drag the setCurrentRowWithKey(String) to the first empty column
in the bottom row of the data table.
You will now have the text select
in that column that is a link. The link won't take the user anywhere yet,
but it will set the current row to the row that they click.
3.
Test the page by running it from the Page Flow diagram.
Click the select link and notice that the * in the first column is displayed
in the row that you click. This shows the current row changing as you
click.
If you want to see a demonstration of the previous steps, click here.
4.
Now that you know that the setCurrentRowWithKey
method is working, you can make the link a little nicer by replacing the
select text with a button.
One of the nice features of the JDeveloper IDE is that you can drag an
image from almost anywhere to the editor window and JDeveloper will incorporate
it in your page.
Add the Edit button by saving this button
to your local disk drive (right-click the image and choose Save Picture
As or Save Image). Save the button_edit.gif to a temporary
directory.
Open Windows Explorer to the directory where you saved the image. Now
drag the image to the editor window and drop it in the middle of the select
text.
The IDE will prompt you to add it to the document root of the application.
Click Yes and save the image in the public_html
directory.
The result should appear like the following:
5.
Next, delete the select
text from around the button. You can do this from either the Design window
or the Source window.
After you have deleted the text, click the button_edit.gif image
to select it. Now go to the Properties palette and set the border
property to 0. This will ensure that the image does not
appear with a blue border around it (indicating that it is a link).
6.
Test the page just as you tested it earlier. Notice that when you click
the image, the current row changes just as it did when it was a text link.
If you want to see a demonstration of these steps, click here.
Now that we have the links and buttons on the pages, it's time to add
the forwards to the Struts Page Flow diagram.
The Struts controller manages page navigation by using events and forwards.
The event notification is specified in the JSP, while the forwards are
defined within the Struts configuration. The Page Flow diagram in JDeveloper
manages the Struts configuration file so you don't have to modify the
file directly.
In the next few steps, you will add forwards to the Page Flow diagram
and modify one link to add an event.
8.
Let's start by adding the forwards to the Page Flow diagram.
Open the Page Flow diagram, then go to the Component palette. Click the
Forward component. To draw a forward from the browseCustomers
node to the editCustomers node, click inside browseCustomers,
then click inside editCustomers. If you want more control over
where the line is drawn, you can click anywhere on the diagram between
the two nodes.
The default name for a forward is success.
To change the name of the forward, click once on the label (success).
Click a second time to edit the label. Change the name of the forward
to Edit.
9.
Now that you have an Edit forward on the page flow, you need to add a
reference to it on the browseCustomers page.
Open the Source editor for the page. Find the Edit button link
that you added earlier. Add the following event code to the link:
By adding this event reference, Struts will call the setCurrentRowWithKey
method, set the current row, and then navigate through the Edit
forward to the editCustomers Page.
You now need to add forwards to get back to the browseCustomers
page.
Add two forwards just as you did for the browseCustomers page. This time
add them from the editCustomers page to the browseCustomers page.
Name the two forwards as follows:
Commit
Rollback
Recall that these were the names of the built-in methods that you added
to the page earlier. The Page Flow diagram should look something like
this:
11.
Test the application. You should now be able to edit rows, commit the
changes, and see them on the browseCustomers page. You should also
be able to make changes, cancel the transaction, and see the unchanged
row on the browseCustomers page.
If you want to see a demonstration of these steps, click here.
Adding
a Create Function
So far, you have created a couple of databound JSPs within
a Struts-controlled application. Those pages enable browsing and editing customer
information. The next step is to add the ability to create customers. JDeveloper
and Oracle ADF provide a built-in function to make this task easy.
There is a demonstration at the end of this section if you
would like to see what the steps look like.
Open the browseCustomers.jsp in the editor window. Select the
Create operation from the Data Control palette. Drag it to the
edit window and drop it within the form tag that contains the Previous
Set and Next Set buttons.
2.
If you run the page now and click the Create button, Oracle ADF inserts
a new blank row into the rowset iterator and stays on the browseCustomers
page. The insert works but it does not do users much good: they can't
add values to the row.
We really want two things to happen: insert a blank row into the rowset,
and navigate to the editCustomers page so that the user can add values
to the new row.
The good thing is that we already have the capability to control navigation
through Struts.
Add a forward to the Page Flow diagram from browseCustomers
to editCustomers and name it Create.
You now have the buttons and navigation in place to insert a new row.
Remember that when you created the TopLink mappings and data control,
you set the CustId attribute to use a database sequence for it's value.
The custId attribute will be populated at commit time.
Later in this workshop, you will change the attribute to make this more
obvious to the user.
3..
Test the new functions by running the browseCustomers page and creating
a new row.
Make sure to leave the Customer ID field blank. TopLink will populate
that value from the sequence at commit time.
Later in this workshop, you will change the display properties of the
field to make it more user friendly.
If you want to see a demonstration of these steps, click here.
Adding
the Delete Function with a Confirmation Page
In this task, you will add the delete
function to the application. We could add the delete function in the same way
that we added the create function, but the default behavior doesn't give the user
a place to confirm the delete. Most applications require that the user be given
the opportunity to confirm a delete action before a row is permanently deleted.
In
this task, you will add a remove button and a confirmation page.
The first step is to create a button
on the browseCustomers page. This button will look like a
button, but it won't actually remove a row. It will do the same thing that the
Edit button does: it will simply set the current row to the row that the user
clicks. Next, it will navigate to the Delete Confirmation page. The delete confirmation
page will hold the delete function.
Add the Remove button to the browseCustomers page just as you
added the Edit button in an earlier step:
Open browseCustomers.jsp
Drag a setCurrentRowWithKey operation as a Find Row Link
to the last column in the last row in the table.
Add the Remove button by saving this button
to your local disk drive (right-click the image and choose Save Picture
As or Save Image). Save the button_remove.gif to to
a temporary directory. Open Windows Explorer to the directory where
you saved the image. Now drag the image to the editor window and drop
it in the middle of the select
text.
The IDE will prompt you to add it to the document root of the application.
Click Yes and save the image in the public_html
directory.
The result should look like the following:
2.
Next, delete the select
text from around the button. You can do this from either the Design window
or the Source window.
After you have deleted the text, click the button_remove..gif
image to select it. Now go to the Properties palette and set the border
property to0. This will ensure that the image does not
appear with a blue border around it (indicating that it is a link).
3.
Test the page to make sure that when you click the remove button ,
the row is set to the current row.
4.
Now that the button sets the current row, you need to add an event (a
chained event) to the link so that when the user clicks the button, Struts
will navigate to the next page in the flow. In this case, you will navigate
to a Delete Confirmation page that you will create shortly.
Open the Source editor for the page. Find the Remove button link
that you just added. Add the following event code to the link:
The button will now set the current row and navigate to the delete event.
In the next task, you will create the Delete Confirmation page and add
the forward to the Struts diagram.
Creating a Delete
Confirmation Page and a Forward
The next task in building the delete process is to create
a Delete Confirmation page and incorporate it into the flow of the application.
Recall that in the previous task you added a button to the browseCustomers page
that sets the current row and navigates to the Delete forward in the Struts
page flow. In this task, you will create the Delete Confirmation page.
There is a demonstration at the end of this section if you
would like to see what the steps look like.
The confirmation page in our application is named sure.jsp.
Create the page just as you created the Edit page earlier.
Double-click /sure on the pageflow diagram
Accept the default name of /sure.jsp.
Add a Read Only Form based on the CustomersWsViewDataControl.
2.
The page needs two buttons to make it complete: confirmation and cancel.
The confirmation button is a databound delete button. Remember that users
access this page only if they click the Remove button on the browseCustomers
page
Although this is a real delete button, we'll disguise it by changing
the label to Yes. It will look to users as if the Remove button on the
browseCustomers page is the delete and that the Yes button is the confirmation,
which is exactly what we want.
Add a Delete button from the Operations node (within CustomersWsViewDataControl).
If you need help, refer to the earlier steps where you added the Create
button.
Change the value property of the button to Yes.
Next add a Cancel button. An easy way to create another button
is to copy and paste the button you just added. After you paste it, double-click
the button to open the edit window. Change the name of the button to event_Cancel
and the value to Cancel.
Add some text to the left of the button that says "Are You Sure?"
Set the style to Heading 4.
3.
You also will need an action binding named 'Commit' that will be bound
to the built-in commit operation of your UI model.
To add the Action:
With sure.jsp active in the Visual Editor, click the UI
Model tab of the Structure window.
Right-click the root node in the tree and choose Create
Binding > Actions > Action from the context menu.
Select your data control (CustomersWSViewDataControl) in the
Data Collection list.
Select Commit as the action using the Select an Action drop-list.
Click OK to continue
Later in the workshop, you will add code to call this commit function.
4.
You can now run and test the form.
Note: Remember that this is a delete confirmation form. If you
click Yes, the row will be deleted, but just from the iterator. You will
add code to call the commit later in the workshop
5.
Now that the confirmation page is functionally complete, we can incorporate
it into the page flow.
Open the Page Flow diagram and add a Forward named Delete
from the browseCustomers page to the sure page.
Next add a Forward named Delete from the sure page
to the browseCustomers page.
The Delete forward from browseCustomers will get the user to the confirmation
page. The Delete forward from the Sure page will get the user back to
the browseCustomers page after a delete.
Next add a Forward named Cancel from the sure page
to the browseCustomers page. This will take the user back to the
browseCustomers page after clicking Cancel.
The Page Flow diagram should now look something like the following:
6.
Run the browseCustomers page. You can now edit rows, create new
customer rows, and delete customers. You can also change your mind and
click Cancel from the Edit and Delete confirmation pages.
All of the basic application functions are now in place. There are a
couple of areas that we still need to address. First, we need to issue
and handle messages that will keep the user informed. Messages like "Customer
nnn has been updated," "Customer nnn has been
deleted," and "Transaction canceled" will keep users from
guessing what just happened and whether they were successful.
We also need to make the pages a a bit more attractive as well as internationalizable.
Struts makes both of these tasks easy.
In the next task, you will address both of these issues.
If you want to see a demonstration of these steps, click here.
The application that you have created
covers all the basic functions we need. We now need to add some messages that
will help users know the status of any actions they choose. If they delete a row,
we want to display a message showing what row was deleted. If they insert a row,
we want to show them that it was successful. Likewise, it they modify a row or
cancel a transaction, we need to display the appropriate message.
Because
the messages are transaction-type specific, we need a way to know and keep track
of which button the user clicked. We will override, or augment, some standard
methods in the Struts action to maintain the transaction type as a session variable.
We will also override a method to interpret the transaction type and create and
store the appropriate message.
The
first step in managing the custom methods for our application is to store the
type of transaction or button click that caused Struts to forward to a new page.
In our case, the starting point (and ending point) of the application is the browseCustomers
page. You will override the dataAction
class and add code to store the transaction type.
Right-click browseCustomers on the Page Flow diagram.
Choose Go To Code from the context menu.
Accept the default name and click OK.
You now have a class that you can use to augment or override standard
methods and behaviors.
2.
In our application, we need to store the transaction type when the user clicks
a button. The way to intercept the button click event is to add a method to this
class with the name onEventName,
where EventName is the name of the event associated with the button or link.
For
example, the Edit button includes event=Edit
in the href. Struts will do several things based on this event. First, it will
look for a method named Edit and
execute it if it exists. Second, it will look for a method named onEdit
and execute that method. And finally, it will look for a forward named Edit and
navigate through that forward.
We can use this pattern and add an onEdit
to our override of the DataAction
class.
Create a new method in the BrowseCustomersAction
class as follows:
public void onEdit (DataActionContext
actionContext) {
}
The argument for this method is a DataActionContext
object. When you enter this code into the class, JDeveloper will prompt
you to import oracle.adf.controller.struts.actions.DataActionContext.
Press [Alt] + [Enter] to add the import statement.
3.
Add an onEdit
method to the BrowseCustomersAction.java
that you created in the first step. You will do only two things in this method:
Store the transaction type in the session variable.
Perform the standard
action.
The code to store the transaction uses the DataActionContext
to get the HTTP Servlet Request and the Session and set an attribute within
the session. The attribute name is type