Académique Documents
Professionnel Documents
Culture Documents
D16975GC10
Production 1.0
May 2004
D39415
Authors
Gary Williams
Lynn Munsinger
Patrice Daux
Technical Contributors
and Reviewers
Jeff Gallus
Pam Gamer
Duncan Mills
Publisher
This material or any portion of it may not be copied in any form or by any means
without the express prior written permission of Oracle Corporation. Any other copying
is a violation of copyright law and may result in civil and/or criminal penalties.
Joseph Fernandez
Contents
Preface
I
Introduction
Objectives I-2
Course Overview I-3
iii
iv
vi
vii
viii
ix
xi
xii
Customizing Actions
Schedule:
Topic
Lecture
Practice
Total
Timing
60 minutes
30 minutes
90 minutes
Objectives
11-2
Objectives
In this lesson, you learn more about Struts components in order to create applications that use the
Struts framework to validate user input from an HTML form. You also learn how to create
applications that contain label references, so that labels can be populated at run time based on the
language settings of the clients browser.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-2
Oracle10g
Forms Developer:
Build
Internet Applications
11-2
11-3
Oracle JDeveloper
10g: Build
Applications
with ADF 11-3
Oracle10g
Forms Developer:
Build
Internet Applications
11-3
/auth
11-4
Creating an Action
An action is an adapter between the contents of an incoming HTTP request and the
corresponding business logic that should be executed to process this request. The action package
is the core of the Struts framework, representing the controller layer of a Model-View-Controller
(MVC) model. All actions are subclassed from org.apache.struts.action.Action.
The XML definition of an action in the struts-config.xml file is:
<action path="/authUser" type="view.AuthUserAction"/>
The path name appearing on the Page Flow Diagram is a logical name, where the name specified
in the Create Struts Action dialog box is the physical name.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-4
Oracle10g
Forms Developer:
Build
Internet Applications
11-4
11-5
Oracle JDeveloper
10g: Build
Applications
with ADF 11-5
Oracle10g
Forms Developer:
Build
Internet Applications
11-5
Forwards
success
/page1
/page2
<action path="/authUser"
type="view.AuthUserAction">
<forward path="/page1.do" name="success"/>
<forward path="/page2.do" name="failure"/>
</action>
11-6
Forwards
Forwards control the flow of an application. One or more forwards are generally defined within
the <action> element in the XML and these, along with any global forwards (defined in the
<global-forwards> section of the XML), are valid places for that action to forward to.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-6
Oracle10g
Forms Developer:
Build
Internet Applications
11-6
11-7
ActionForward
The programmer has to return a reference to a forward from the execute() method in the
action. This is done by using the findForward() method, which accepts the name of the
forward to return to.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-7
Oracle10g
Forms Developer:
Build
Internet Applications
11-7
11-8
Global Forwards
A global resource, such as a global forward or a global exception, can be used at any time by any
resource.
The links to a global forward are not represented on the page flow.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-8
Oracle10g
Forms Developer:
Build
Internet Applications
11-8
Form Beans
Logon
User Name
Password
Logon
Submit
authUser
Populates
logonBean
menu
11-9
Form Beans
Form beans are associated with one or more actions. When a page is submitted to the action, the
Struts controller matches parameters from the request object with fields in the form bean class
and populates the bean.
The developer is passed the form bean reference as a parameter to the execute() method of
the action class, and the values are accessible through get() methods. This saves the developer
from having to query the request. More importantly, the bean can be populated before a page is
displayed and the fields in the page are prepopulated with the relevant fields from the bean that
match the field names in the HTML formso the process works both ways.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-9
Oracle10g
Forms Developer:
Build
Internet Applications
11-9
Form Beans
Can be dynamic:
Each field specified in struts.config.xml
Does not require Java code
11-10
Oracle JDeveloper
10g: Build
Applications
with ADF 11-10
Oracle10g
Forms Developer:
Build
Internet Applications
11-10
/authUser
11-11
Oracle JDeveloper
10g: Build
Applications
with ADF 11-11
Oracle10g
Forms Developer:
Build
Internet Applications
11-11
11-12
Oracle JDeveloper
10g: Build
Applications
with ADF 11-12
Oracle10g
Forms Developer:
Build
Internet Applications
11-12
11-13
Oracle JDeveloper
10g: Build
Applications
with ADF 11-13
Oracle10g
Forms Developer:
Build
Internet Applications
11-13
11-14
Oracle JDeveloper
10g: Build
Applications
with ADF 11-14
Oracle10g
Forms Developer:
Build
Internet Applications
11-14
11-15
Oracle JDeveloper
10g: Build
Applications
with ADF 11-15
Oracle10g
Forms Developer:
Build
Internet Applications
11-15
Logon
failure
authUser
success
<action-mappings>
<action path="/logon
forward="/logon.jsp"/>
<action path="/authUser"
name="logonBean"
type="view.AuthUserAction">
<forward
path="/logon.do
name="failure"/>
<forward
path="/menu.do
name="success"/>
</action>
<action path="/menu"
forward="/menu.jsp"/>
</action-mappings>
menu
11-16
Oracle JDeveloper
10g: Build
Applications
with ADF 11-16
Oracle10g
Forms Developer:
Build
Internet Applications
11-16
Logon
failure
authUser
success
menu
11-17
<action path="/authUser"
name="logonBean"
type=" view.AuthUserAction ">
<forward
path="/logon.do
name="failure"/>
<forward
path="/menu.do
name="success"/>
</action>
<action path="/menu"
forward="/menu.jsp"/>
</action-mappings>
Oracle JDeveloper
10g: Build
Applications
with ADF 11-17
Oracle10g
Forms Developer:
Build
Internet Applications
11-17
Logon
<action path="/authUser"
name="logonBean"
type=" view.AuthUserAction ">
failure
<forward
path="/logon.do
name="failure"/>
authUser
success
menu
11-18
<forward
path="/menu.do
name="success"/>
</action>
<action path="/menu"
forward="/menu.jsp"/>
</action-mappings>
Oracle JDeveloper
10g: Build
Applications
with ADF 11-18
Oracle10g
Forms Developer:
Build
Internet Applications
11-18
Logon
Password
Logon
failure
Submit
authUser
success
logonBean
menu
11-19
Oracle JDeveloper
10g: Build
Applications
with ADF 11-19
Oracle10g
Forms Developer:
Build
Internet Applications
11-19
Logon
failure
<form-beans>
<form-bean
name="logonBean
type="org.apache.struts.
action.DynaActionForm">
authUser
success
menu
11-20
<form-property
name="username"
type="java.lang.String"/>
<form-property
name="password"
type="java.lang.String"/>
</form-bean>
</form-beans>
Oracle JDeveloper
10g: Build
Applications
with ADF 11-20
Oracle10g
Forms Developer:
Build
Internet Applications
11-20
Logon
Password
Logon
failure
authUser
Passed to
Submit
Populates
success
logonBean
menu
11-21
Oracle JDeveloper
10g: Build
Applications
with ADF 11-21
Oracle10g
Forms Developer:
Build
Internet Applications
11-21
11-22
Oracle JDeveloper
10g: Build
Applications
with ADF 11-22
Oracle10g
Forms Developer:
Build
Internet Applications
11-22
Logon
Password
Logon
failure
authUser
Passed to
Submit
Populates
success
logonBean
menu
11-23
Oracle JDeveloper
10g: Build
Applications
with ADF 11-23
Oracle10g
Forms Developer:
Build
Internet Applications
11-23
11-24
Oracle JDeveloper
10g: Build
Applications
with ADF 11-24
Oracle10g
Forms Developer:
Build
Internet Applications
11-24
Summary
11-25
Summary
In this lesson, you should have learned the XML syntax for the content of the strutsconfig.xml file. Additionally, you should have learned about advanced Struts components,
such as actions and form beans, and how to support internationalization of a Struts application.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-25
Oracle10g
Forms Developer:
Build
Internet Applications
11-25
11-26
Oracle JDeveloper
10g: Build
Applications
with ADF 11-26
Oracle10g
Forms Developer:
Build
Internet Applications
11-26
Practice 11-1
In this practice, you create a form bean to hold logon information. That logon information is
passed to an action that performs authentication and returns a customer name if the validation
succeeds.
Start JDeveloper, and open the practice11 workspace.
1. Create form beans.
a. Open the Page Flow Diagram.
b. In the Structure pane, create a new Form Bean.
c. In the Property pane, specify logonBean as the name and set the type to
org.apache.struts.action.DynaActionForm.
d. In the Structure pane, select the logon bean and create a new Form Property.
e. In the Property Inspector, set the name property to lastName and leave it as a
String.
f. Create a second Form Property for customerId (leave it as a String).
2. Create a new view object that validates the customer logon. This view object will accept
two parameters and query the customers table for a combination of both
customerLastName and customerId.
a. Create a view object. Name it AuthenticateView. Remember to create the view
object in the Model project.
b. Select customers as the entity object.
c. Select customerId, custFirstName, and custLastName as the attributes.
d. Add a WHERE clause that compares the upper of custLastName with the upper of
a parameter AND compares customerId with a second parameter.
SELECT Customers.CUSTOMER_ID,
Customers.CUST_FIRST_NAME,
Customers.CUST_LAST_NAME
FROM CUSTOMERS Customers
WHERE upper(Customers.CUST_LAST_NAME)= upper(?)
and Customers.CUSTOMER_ID= ?
e. Make sure to select the Use ? Style parameters check box if you are using the above
syntax.
f. In step 6 of 6, select the Generate Java File option for the View Row class.
g. Click Finish to validate.
h. Add the view to SalesAppModule and remove 1 from the instance name.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-27
Oracle10g
Forms Developer:
Build
Internet Applications
11-27
Oracle JDeveloper
10g: Build
Applications
with ADF 11-28
Oracle10g
Forms Developer:
Build
Internet Applications
11-28
9. Run the application starting at the welcome page. Try to log on with the following values
of CustomerLastName and CustomerId:
Welles
101
Pacino
102
Taylor
103
10. You will enhance this validation in a later practice.
Oracle JDeveloper
10g: Build
Applications
with ADF 11-29
Oracle10g
Forms Developer:
Build
Internet Applications
11-29
Oracle JDeveloper
10g: Build
Applications
with ADF 11-30
Oracle10g
Forms Developer:
Build
Internet Applications
11-30
Schedule:
Topic
Lecture
Practice
Total
Timing
30 minutes
45 minutes
75 minutes
Objectives
12-2
Objectives
Databound applications that contain Oracle ADF business services are created by using data
actions. This lesson discusses how data actions are created, customized, and utilized in a
databound application.
12-3
12-4
12-5
12-6
12-7
Displaying Data
12-8
Displaying Data
The next step in utilizing data pages is to develop the JSP that contains the bound data. Utilize
the Data Control Palette to add data, navigation, and operations to the JSP. Note that the first
time you add a data control to the page, the mappings for all data controls are automatically
generated and contained in DataBindings.cpx.
Displaying Data
Generated code
<c:forEach var="Row"
items="${bindings.CustomersView1.range
Set}">
<tr><td>
<c:out value="${Row.CustomerId}">
</c:out></td>
12-9
12-10
/addCustomer
<action path="/addCustomers"
<set-property property="methodName"
value="addCustomersUIModel.Create"/>
</action>
12-11
setCurrentRowWithKey
Delete
12-12
12-13
5. Process updates
6. Validate updates
7. Handle model and UI events
12-14
12-16
Defined by:
Dragging operation from the Data Control Palette
Explicit creation in the Structure pane
Invoked by:
Button with the name event_<operation>,
for example, event_Commit.
Hyperlink with a parameter event=< operation>,
for example, event=Commit.
12-17
Invoked by:
12-18
12-19
12-20
<html:form action="/addCustomers.do">
12-21
Summary
12-22
Summary
This lesson should have taught you how to utilize data pages and data actions to easily
incorporate business services into a Struts-based Web application.
12-23
Practice 12-1
Adding features to data pages.
Start JDeveloper, and open the practice12 workspace.
1. In this step, you add navigation operations to the categories page. The buttons allow the
user to navigate forward or backward through sets of category rows.
a. Open the categories data page.
b. In the Data Control pane, open the SalesAppModuleDataControl node, expand the
CategoriesView node, and then the Operations node.
c. Select the Previous Set item, and drag it to the Design Editor following the last
object. If prompted with an Add Form Element Confirmation dialog box, answer Yes.
d. Perform the same steps and add the Next Set operation, and drag it next to the
Previous Set button.
e. You must include the data table inside the form tag that you just added. Go to the
Source tab, find the <form> tag, and move it to just above the <table> tag.
f. Next, set the action property of the form to categories.do.
2. Modify the iterator so that the page does not display all the items at one time. This makes
the pages more user friendly. If the users do not see the category that they are looking for,
they can click one of the buttons to see the next set of records, rather than having to scroll
to see all of the categories.
a. In the Applications Navigator, click the categories.jsp node.
b. In the Structure pane, click the UIModel tab, which is the second tab at the top of the
Structure pane.
c. Click CategoriesViewIterator and set the Range Size value to 5 in the Property
Inspector. This restricts the number of categories displayed on a page to 5.
3. Add navigation operations to the products page.
a. Open the products data page.
b. Within the CategoriesView node, expand the ProductInformationView node, and
then the Operations node and add Previous Set and Next Set items as you did for the
categories page. Do not forget to move the <form> tag and set the action property to
products.do.
4. Modify the products iterator to display 5 rows just as you did for the categories iterator.
5. Clean up the unnecessary columns from both pages.
a. In the table created for the view, select the first top left cell, right-click, select Table
from the context menu, and select the delete column option.
b. This removes the current_row column from the table.
e. The cartTotal() method returns the total of all the items in the cart. To do this, it
creates a rowSetIterator of the shoppingCart and iterates through it,
summing the extendedTotal attributes as it does. At the end of the
RowSetIterator, it returns the total.
Schedule:
Topic
Lecture
Practice
Total
Timing
35 minutes
30 minutes
65 minutes
Objectives
13-2
Objectives
Business logic and rules should be enforced in the business tier of an application. However, it is
possible and sometimes useful to validate data at the client level (thus saving the user a round
trip to the server). This provides for an effective and robust user interface. This lesson shows you
how to incorporate client-side validation into the view of a Struts-controlled application.
Additionally, enhancing the view by using control hints is also covered in this lesson.
Overview of Validation
Form Bean validate()
method, Struts Validator
JSP
JavaScript
13-3
Struts
Form Bean
Method Validators,
Control Hints
Struts
Action
ADF
Business
Components
Overview of Validation
Validation can be performed at many levels of an application. You have already seen how to
create validation methods in ADF Business Components by using method validators. However,
there are several ways to incorporate validation in Struts: utilizing the form bean validate()
method, or by creating custom validation classes and calling their methods from the
execute() method of a Struts action. There is also a plug-in available in Struts, which
incorporates common validation rules. Additionally, simple validation can be performed at the
client level by creating a JavaScript file, which is referenced in the JavaServer Pages (JSP).
13-4
Client-Side Validation
13-5
Client-Side Validation
Validation can be incorporated by using the form bean class of a Struts action. The form bean
contains a validate() method, where you can define the validation logic. The next step is to
create a message for the error in the ApplicationResources.properties file.
13-7
<body>
<html:errors />
13-8
Specific <html:errors>
(property attribute set)
Validating Actions
13-9
Validating Actions
Instead of validating form input by using the validate() method, you can also validate
values by using the execute() method of the action. This is especially useful if you already
have JavaBeans or other classes that evaluate user input.
13-10
13-11
Validation Results
13-12
Validation Results
The validation incorporated thus far in this lesson ensures that the user enters something in the
username and password form fields (case 2). When that validation has occurred, the action
validates the entered username to ensure that it is a valid login (Scott, Tiger). If not, the
failure forwards to the original login form (case 1). Finally, if the user enters the correct login,
the user is forwarded to the success page (case 3).
Struts Validator
13-13
Struts Validator
Validator is driven by two XML files, validator-rules.xml and validations.xml.
validator-rules.xml describes all the validation rules that can be used, such as
required, maxLength, integer, and so on.
Each rule is defined in validations.xml, which applies rules to the various fields in a form
bean. If validation fails, the user is redirected to the input page with the relevant error messages
from the validator. Note that validator-rules.xml is extensible. You can add custom
validation rules by utilizing the appropriate classes to implement them.
Besides for server-side validation, validator-rules.xml can also have a JavaScript
component for client-side validation.
13-14
13-15
13-16
validation.xml: Example
13-17
validation.xml: Example
In this example, the form bean named logonbean is validated by using the built-in validation
rule required. At run time, the validator checks for a value in the password field, and if it is
null or an empty string, the key logon.password is referenced in the
ApplicationResources.properties file and this value is passed as an argument to the
errors.required entry. Some of the additional built-in validation rules and their
corresponding error message keys are described in the table below:
Built-in Validation Rules
("depends" attribute)
range
byte/short/integer/long/
float/double
date
creditCard
13-18
Exception Handling
13-19
Exception Handling
Exception handling is implemented in the case that an actions execute() method throws an
exception by creating a class for the exception, which subclasses ExceptionHandler.
Override the execute() method to process the exception, and return an ActionForward
object. Next, configure the exception handler in the struts-config.xml file. This can be
done globally:
<global-exceptions> <exception
key="exception.message.global" type="java.io.IOException"
handler="view.MyExceptionHandler"> </global-exceptions>
Or for a specific action:
<action>
<exception type="java.io.IOException"
key="exception.message.action"
handler="view.MyExceptionHandler" />
</action>
The last step is to map the key attributes to an appropriate error message in
ApplicationResources.properties.
JavaScript
JavaScript is supported
in JDeveloper as a
simple way to
incorporate validation.
13-20
JavaScript
A simple way to incorporate additional validation in a Web application is to use JavaScript.
Code insight and highlighting are supported in JDeveloper for JavaScript (.js) files. JavaScript
validation is best used for simple validations such as verifying that a user enters a number in a
number field. However, careful consideration must be given to the extensive use of JavaScript,
as clients can turn off JavaScript in their browser. In this case, validation should be duplicated by
using form bean validation or the Struts Validator so that the user cannot enter invalid or
incorrect data.
13-21
Note that if a control hint is defined for an entity attribute, all view objects of that entity will
inherit the control hint. However, a view object attribute can override any entity attribute control
hints.
Summary
13-22
Summary
This lesson should have taught you how to incorporate validation in the controller and view tiers
of an application. Additionally, you should have learned how to customize the view through the
use of ADF Business Component attribute control hints. These types of development objectives
aid the user in successfully navigating through a Web application.
13-23
Practice 13-1
In this practice, you enhance the views and create a new view.
Start JDeveloper, and open the practice13 workspace.
1. Enhance the view objects to make the the UI more user-friendly.
Hint: To edit the view objects, double-click the view object in the System Navigator.
Expand the attribute list, and select the attribute you need to change. Click the
Control Hints tab and make the necessary changes.
a. Edit the CreditLimit attribute in CustomersView. On the Control Hints tabbed page,
set the format type to currency and format to $0000.00.
b. Edit the UnitPrice and DiscountUnitPrice attributes in OrderItemsView. Set the
format type to currency and format to $0000.00.
c. Edit the OrderDate attribute in OrdersView. Set the format type to Simple Date and
format to yyyy-mm-dd.
d. Edit the ListPrice attribute in ProductInformationView. Set the format type to
currency and format to $0000.00.
e. Edit the ListPrice and ExtendedTotal attributes in ShoppingCartView. Set the
format type to currency and the format to $0000.00.
2. Add a validator for input fields by adding the validator plug-in to the Strutsconfig.xml file.
a. Open the Page Flow Diagram.
b. In the Structure pane, right-click the the top-level Struts Config node and choose New
> Plug In from the context menu. This will create a new plug-in node in the structure.
c. Select the new plug-in node and switch to the Property Inspector.
d. Set the className property for the plug-in to
org.apache.struts.validator.ValidatorPlugIn.
e. Now with the plug-in node still selected in the Structure pane bring up the context
menu and choose New > Set Property. This will create a child node under the plugin labeled as <set-property>.
f. Select the new <set-property> entry and switch to the Property Inspector.
g. Set the property property for this <set-property> entry in the inspector to path
names.
h. Set the value property to the following (this can be changed to suit your application):
/WEB-INF/validator/validator-rules.xml,/WEBINF/validator/validations.xml.
3. Modify the authenticateUser Data Action to use the logon Form Bean you created in an
earlier practice.
a. Select the authenticateUser Data Action on the Struts diagram.
b. Change the input property to /logon.do.
c. Change the name property to logon.
4. Set up form beans to use the correct superclass.
a. Open the Page Flow Diagram.
b. In the Structure pane, open the logon Form Bean.
c. In the Properties pane, change the type to
org.apache.struts.validator.DynaValidatorForm.
d. Select the WEB-INF/validator node in the Applications Navigator. Note that there is
a file named validations.xml. This file holds the validation rules that you are
going to apply. Normally, you create this file by selecting the WEB-INF node, rightclicking, and selecting New from the context menu. You then select xml, new xml
file in the gallery.
e. Open the validations.xml file and examine the code. You should note that the
statements check whether the customerName field has a value and that the
customerId field is required, and whether it is an integer and has a value between
100 and 600. The xml validation code is on the following page.
d. Update the JSP to use JavaScript validation by inserting the following statement right
below the <head> tag:
<html:javascript formName="logon"/>
Schedule:
Topic
Lecture
Practice
Total
Timing
45 minutes
45 minutes
90 minutes
Objectives
14-2
Objectives
After the fundamental application is complete, you can begin to enhance the user interface (UI)
with additional elements. These elements can be either visual or databound elements.
In this lesson, you learn how to add elements that enhance the UI. You also learn how to add
navigational elements.
14-3
Property Inspector:
Style
poplist
Font
poplist
Font
size
Bold/
italic/
underline
14-4
Foreground
color
Align left/
center/right
Background
color
Numbered/
bulleted
list
Decrease/
increase
indent
14-5
14-6
14-7
14-8
CSS File
untitled1.css
14-9
14-10
14-11
14-12
14-13
14-14
DepartmentsView1
Drop As:
Navigation Buttons
14-15
Cursor
14-16
14-17
14-18
You can concatenate multiple expressions with static text. For example:
<c:out value="Hello ${customer.firstName} ${customer.lastName}"/>
Using EL Attributes
To reference attributes:
Enclose within ${}
Nest by using dot notation or []
<c:out value=
"${sessionScope.cart.numberOfItems} ">
14-19
Using EL Attributes
You can access attributes by name, with an optional scope. Use dot notation or brackets ([]) to
access properties of attributes, which may be nested. For nested expressions, the value that is
returned is dependent on the type of object. For example, for the expression ${exp1.exp2}, if
exp1 is:
A map, the value that is returned is exp1.get(exp2)
A list or array, exp2 is coerced to an int and the value of the indicated list or array
member is returned
A JavaBean object, exp2 is coerced to a String and the result of a getter call is returned
You can specify a scope for the attribute. If no scope is specified, an attribute identifier is first
checked against page scope, then request scope, session scope, and finally application scope. If
the attribute is found, the value of the first match is returned; if not found, null is returned.
Operators
14-20
Description
The PageContext object
A map that maps page-scoped attribute names to their values
A map that maps request-scoped attribute names to their values
A map that maps session-scoped attribute names to their values
A map that maps application-scoped attribute names to their values
A map that maps parameter names to a single String parameter value
A map that maps parameter names to a String[] of all values for that
parameter
A map that maps header names to a single String header value
A map that maps header names to a String[] of all values for that
parameter
A map that maps a parameter name to a single String parameter value
14-22
Summary
14-23
Summary
In this lesson, you should have learned how to enhance the user interface in the following ways:
By using the Property Inspector to modify visual components
By using the Structure pane to modify data elements
By using EL to add conditional display logic to your page
14-24
Practice 14-1
At this point, the pages that you have built are displayed by using a default presentation, which is
not bad, but probably is not good enough for an enterprise application. In this practice, you add a
few things that make the pages more user-friendly.
Start JDeveloper, and open the practice14 workspace.
1. Create a heading page.
a. In the Page Flow Diagram, create a JSP page and name it /heading.jsp.
b. Add Welcome to the top of the page. Use a messageBean for consistency.
c. Next, add a JSTL out tag to get sessionScope.customerName.
${sessionScope.customerName}
d. In the Component Palette, select CSS from the list and drag the JDeveloper CSS to
the page.
2. Include the heading page in all pages.
a. Select the logon page.
b. Select the JSP jsp:include tag and drag it to the top of the page.
c. Use the Browse button to find and select the heading page.
d. Repeat the operation for the categories, products, and shoppingCart pages.
3. Update the CSS to make your read-only tables more readable.
a. Select the CSS | jdeveloper.css node in the Web Content folder.
b. In the Structure pane, select the TH node.
c. In the Property Inspector, set the background-color value to #336699 or a color of
your choice.
d. Set the color to White.
e. Set the font-style key to italic, font-weight to bold and text-align to center.
4. Update the categories page to use messageBeans for the headings.
a. Open the ApplicationResources file and add the following entries. Save the
file when you are done:
category.id= Category Id
category.name= Name
category.description= Description
b. Open the categories page in the Design Editor.
c. If there is a currency column in the read-only table, select it and
remove it (right-click | table | Delete Column).
d. It there is no title message bean, add it. Set the title message bean style to Heading1
(H1). Make sure to exclude the jsp:include and error tags from the H1 style.
Schedule:
Topic
Lecture
Practice
Total
Timing
45 minutes
45 minutes
90 minutes
Objectives
15-2
JAAS Provider
15-3
JAAS Provider
The JAAS provider supports management of realm information, which contains user and role
properties. It also manages policy information, which it uses to determine who can do what in an
application. JAAS uses a repository to keep all this run-time information. The repository can be
either a Lightweight Directory Access Protocol (LDAP)based repository or an XML file. A
JAAS provider also uses login modules for obtaining user information.
JAAS works with the Java 2, Enterprise Edition (J2EE) declarative security model. This model
runs with a J2EE application container and is part of the deployment model. It can be
implemented with little or no programming.
15-4
JAZNUserManager
Obfuscates passwords in flat file storage
Supports full role-based access control
Supports full support for Java 2 permissions model
15-5
Client Authentication
Authentication:
Determines who clients are
Can they prove it?
15-6
Client Authentication
Authentication is the part of JAAS that ensures that the given users (principals) are who they say
they are. This is the first part of the security model. After users are identified and it is verified
that they are who they say they are, they are considered authenticated. The next step is to check
what they are authorized to do.
JAAS integrates with well-known and used authentication schemes.
SSO: An Oracle feature that integrates with an application deployed to OracleAS. The
authentication and authorization is specified and controlled by deployment descriptor files
on the server.
SSL: This authentication scheme is based on using certificates that are passed from a
browser and validated by the application.
Basic: The user is prompted for a username and password. The values are validated by a
login module.
Write your own login module: You can write your own login module to authenticate
against any data source or authentication mechanism. These modules can include any type
of authentication, including biometrics, smartcards, and others.
Client Authorization
15-7
Client Authorization
The security roles that are defined by the application assembler provide the deployer with a
logical and simplified security view of the Web application. The deployer is responsible for
mapping the logical security roles to principals or to groups of principals that are defined in the
target operational environment.
At run time, a client is allowed to access a URL or invoke a business method only if the principal
making the request is authenticated and authorized (by being associated with an appropriate
security role) to access the requested resource. The container provider enforces the security
policies at run time and provides the tools for managing security during deployment and at run
time.
The security view defines the various types of users of the application and their rights to invoke a
URL request or methods in the enterprise bean interfaces.
Note: The security roles define the logical security view of an application. They should not be
confused with the user groups, users, principals, and other concepts that exist in the target
enterprises operational environment.
The security roles and information are configured and mapped in configuration files and
deployment descriptors.
Servlet 1 Servlet 2
OracleAS
JAAS
OracleAS
JAZN Provider
JAZNUserManager
JAAS
HTTP Server
15-8
OracleAS
JAAS Policy
15-9
15-10
web.xml Properties
15-11
web.xml Properties
The web.xml file holds information used by the J2EE container to provide security services.
One of the properties is the security roles that are authorized to use the application. The users (or
principals) that belong to these roles are defined in the jazn.xml file that you looked at in an
earlier lesson.
Next, specify a Web resource name to which security properties will be applied. This Web
resource must have a unique name, which should include a URL pattern that will be validated
and the user role that will be allowed to use the resource.
Note that URL patterns are used for the original request, and not on internal subsequent calls
such as <jsp:include> and <jsp:forward>. It is assumed that your application will not
forward a user request to any unauthorized page.
web.xml Results
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>TestApplication</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>users</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>users</role-name>
</security-role>
</web-app>
15-12
web.xml Results
In this portion of the web.xml file, you can see that the authorization entries are added. These
entries are used by the J2EE container to enforce your security constraints.
15-13
Adding Users
15-14
Adding Users
From this dialog box, you can add, remove, and edit users within a realm. To add a user, click
the Add button and complete the Name and Credentials fields. This will be the username and
password for this user. The next step is to assign this user to a role or roles.
Managing Roles
15-15
Managing Roles
Access to application resources is controlled through roles. Each user participates in one or more
roles. In this dialog box, you can define roles and add or remove users from roles.
15-16
15-17
Summary
15-18
Practice 15-1
In this practice, you will change the logon routine to use JAZN security authorization.
In earlier practices, you used a method in the SalesAppModuleImpl class to find customer
information based on a logon page. The method accepted a username and password, performed a
lookup in the Customers table, and returned a concatenated username. You then used that name
to display in the heading for each of the pages in your application. Now you will use another
method that gets the user ID from JAZN.
Start JDeveloper, and open the practice15 workspace.
1. First, you will configure the application to use JAZN security for authentication.
a. Right-click the web.xml file and select properties to edit the deployment descriptor.
b. Select the Login Configuration node and then select HTTP Basic Authentication for
the authentication type.
c. Add a new security role by selecting the Security Roles node. Click the Add button
and enter users as a new role.
d. Next add a security constraint by clicking the Security Constraint node and clicking
the New button at the bottom of the navigator.
e. Add a new Web resource and name it SalesApp.
f. Add a URL pattern and set the value to /.
g. Next, click the Authorization tab, and click users to authenticate that group to your
application.
h. Test the application. You can right-click on any page on the pageflow diagram and
select run. Because the entire application is protected, anywhere you choose to start
will require a JAZN logon. The valid user IDs are user with the password of 456,
SCOTT with a password of TIGER, and anonymous with any character as a
password. Try to use an invalid ID or password.
2. Now that you have JAZN working to authenticate users, add an action that will use the
JAZN authenticated user ID to look up customer information and store it in
sessionScope.customerName.
You will add a new path to the categories page, which will use this DataAction. In reality,
you may replace the current authenticateUser DataAction with this new one, but you
should be able to compare the two techniques.
a. Add a DataAction to the Page Flow Diagram, and name it authenticateUserJAZN.
You can do this on the diagram or change path in the Property Inspector
b. Expand the SalesAppModule node in the Data Control Palette, and drag the
findCustomerJAZN method to the new DataAction.
c. Select the authenticateUserJAZN node in the Structure pane and change the
resultLocation value to {sessionScope.customerName}. This will put the
results of the findCustomerJAZN method into the session variable customerName.
d. Add a page link from the Welcome.jsp page to the new DataAction.
e. Add a forward from the DataAction to the categories page.
Schedule:
Topic
Lecture
Practice
Total
Timing
45 minutes
30 minutes
75 minutes
Objectives
16-2
Objectives
This lesson introduces ADF UIX. The lesson shows you how to build a UIX XML page and add
data components. The lesson explores the structure of a UIX XML page. The design-time
environment, including the Visual Editor, Data Component Palette, and Property Palette, is
examined.
Design-time benefits
Run-time benefits
16-3
Servlet
View
Controller
Model
Any data source
16-4
UIX Page
16-5
Markup
1.
2.
3.
4.
5.
16-6
Page Header
Tabs and Navigation
Global Buttons
Data Component Area
Page Footer
Interface Nodes
16-7
How Is It coded?
UIX XML is a dialect of the XML language for creating ADF
UIX pages declaratively.
16-8
16-9
16-10
16-11
16-12
16-13
Branding a Page
Company Branding
Use a wizard page to specify the Corporate Branding image and associated link for the new UIX
XML pages. Click Select Image to select the image that you want to use in the Corporate
Branding section in the top left area of the page. Enter the destination URL that will execute
when the user clicks the Corporate Branding image specified above.
Product Branding
This dialog box is similar to Corporate Branding. Use it to specify the Product Branding image
and associated link for the new UIX XML pages. Click Select Image to select the image that you
want to use in the Product Branding section in the top left area of the page. Enter the destination
URL that will execute when the user clicks the Product Branding image specified above.
Page Tabs
16-14
Global Buttons
16-15
Page Footers
16-16
16-17
16-18
16-19
Run-Time Deployment
UIX XML applications created in Oracle JDeveloper 10g can be deployed directly from the
integrated development environment (IDE).
By default, JDeveloper runs applications in the embedded OracleAS 10g Containers for J2EE
(OC4J) server to enable testing and debugging before deploying to a target application server.
The supported application server connection types are:
Standalone OC4J
OracleAS 10g via local Distributed Configuration Management (DCM)
OracleAS 10g via remote DCM
Deploying UIX XML applications to OracleAS 10g is completely automated in JDeveloper. For
example, when you create an ADF Business Component UIX XML application, JDeveloper
automatically generates a Web Application Archive (WAR) file that contains both the ADF
Business Components and the UIX XML application files. A deployment descriptor file and a
WAR deployment profile are also created.
16-20
16-21
16-22
16-23
Summary
16-24
16-25
Tab Text
Tab Destination
Customers
Products
Details
Destination URL
Image Location
Cart
..\public_html\images\cart.gif
Help
..\public_html\images\help.gif
Logon
..\public_html\images\login.gif
Schedule:
Topic
Lecture
Lab
Total
Timing
45 minutes
30 minutes
75 minutes
Objectives
17-2
Overview
Servlet/JSP/HTML
Packaging
Deployment
Libraries, Packages
17-3
Overview
The final destination for your servlet or JavaServer Pages (JSP) is a Web server. You may have a
large number of classes and libraries in your application. In this lesson, you learn how to package
these various entities and deploy them to OC4J. Up to this point, servlets and JSP pages have
been tested by running them in the embedded OC4J server installed with Oracle JDeveloper 10g.
This lesson discusses deployment to a remote OC4J server in a production environment.
17-4
17-5
Archive Type
Module Type
Software Content
Java Application
components
EJB JAR
Enterprise
JavaBeans (EJB)
components
Servlets and
JavaServer Pages
(JSP) components
Enterprise Archive
(EAR)
Not applicable
J2EE application
Archive Formats
JAR, EJB JAR, and WAR files each contain a module consisting of one or more components.
An Enterprise Archive (EAR) file contains an application consisting of one or more packaged
modules. According to the J2EE specification, every application must be assembled and
packaged as an EAR file before deployment to a J2EE server.
When you create a Web (servlet or JSP) or EJB application and deploy it via an application
server connection, JDeveloper packages it as a WAR or EJB JAR wrapped in an EAR file.
If your application consists of components of different types, the components are packaged into
multiple modules, and you must create an EAR deployment profile to assemble them as an EAR
file.
17-6
Deploying to OC4J
17-7
Deployment to OC4J
To deploy to OC4J from JDeveloper, install OracleAS 10g version 10.
Start OC4J by issuing java jar oc4j.jar from the <iASHome>/j2ee/home
directory, where iAS installs OC4J. JDeveloper automatically creates an archived WAR file for
use in deployment to OC4J. The name of this file defaults to <webapp1.deploy> and
contains your project class files, libraries, and database connection information. Your project is
easily deployed from JDeveloper to OC4J by creating a connection to the remote OC4J server,
and right-clicking the .deploy file and selecting Deploy.
Install OC4J
17-8
Install OC4J
Install OC4J from a command window that is open and in the <ias_home>/j2ee/home
directory. <ias_home> is usually JDeveloper/j2ee. The java jar oc4j.jar
install command unpacks and installs OC4J. You are required to enter a password for the
OC4J administrator, which you need when deploying from JDeveloper.
17-9
17-10
17-11
17-12
Deploying to OC4J
17-13
Deploying to OC4J
When the connection is created, deploying to OC4J is simple. Right-click the deployment
profile, and select Deploy to > <yourappserverconnection>. Additionally, connections to other
J2EE servers can be created, and applications are deployed to those servers in the same way.
Instructor Note
At this point, you may want to deploy an application, such as lesson17.jpr. Create an OC4J
connection, then right-click the .deploy file to deploy. This course does not include
Oracle9iAS; therefore, students should use a remote OC4J connection by manually starting the
OC4J server included with JDeveloper. Your ability to demonstrate deployment to a truly remote
iAS install will depend on what you have installed on your laptop, but the procedure is the same
for both instances.
Running Applications
17-14
Customizing Deployment
17-15
Customizing Deployment
As we have seen, deployment profile uses the project name to identify the application.
Optionally, change the name, context root, and war file names in the Profile Settings dialog box.
Summary
17-16
17-17
Practice 17-1
The purpose of this practice is to deploy a Struts application to OC4J. You will be manually
deploying the application created in practice 14 to a local OC4J server. The OC4J server will
actually be that which is installed with Oracle9i JDeveloper, but the deployment steps are the
same for a production deployment.
1. The ADF framework requires version 1.4 of the Java run time. To make sure that this is the
default version on your machine, run java version from a command prompt. If the
version is not 1.4, change your path statement to ensure that the correct version is used. The
1.4 Java run time is delivered with JDeveloper and is the directory
<Jdev_Home>/jdk/bin.
2. First, install the OC4J server.
a. Open a command prompt and navigate to the <JDEV_Home>/j2ee/home
directory. This is where the OC4J server is installed.
b. Type java -jar oc4j.jar install at the prompt to start the install of the
OC4J server.
c. Specify a password that you want to use (that is, admin).
d. Confirm you password.
3. Next, start the OC4J server.
a. Open a command prompt and navigate to the <JDEV_Home>\j2ee\home
directory. This is where the OC4J server is installed.
b. Type java -jar oc4j.jar at the prompt to start the OC4J server.
c. The server will automatically deploy any .war files that were included in the
deployment directories at install, and when finished will display Oracle
Application Server Containers for J2EE 10g (9.0.4.0.0)
initialized Oracle9iAS (9.0.2.0.0) Containers for J2EE
initialized.
4. Next, create a connection to the OC4J server.
a. Click the Connections tab on the navigator pane. Right-click Application Server and
select New Application Server Connection from the context menu.
b. Name the new connection OC4J, select the StandaloneOC4J type, and click Next.
c. Supply the username and password for the OC4J Connectionthe admin password
is the one that you have specified at install. Select the Deploy Password check box,
and then click Next to continue.
d. Accept the default ormi mappings for the server, and click Next.
e. Test the connection to ensure that the server is running and the username and
password are valid.
5. Set the Welcome.jsp as the default run target for the application.
a. Open the Page Flow Diagram for the application.
b. Right-click welcome.jsp on the diagram.
c. Choose Set as Default Run Target from the context menu.
6. Now create a deployment profile for the application.
a. Right-click the ViewController node, and select New from the context menu.
b. Create a New deployment profile using war file.
c. Specify shoppingApp as the deployment profile name.
d. Click OK to close the Deployment Profile Wizard.
Course Schema
Course Schema
Database Scripts
These SQL scripts are used to modify the default OE schema to meet course requirements.
Add status and discount columns
alter table order_items add (
discount_unit_price number(8,2));
update order_items set discount_unit_price =
(select list_price from product_information where
product_information.product_id = order_items.product_id);
alter table customers add (
status varchar2(10));
update
update
where
update
where
Practice Solutions
Practice 2-1
1. Start JDeveloper 10g, and open the practice02sol workspace.
a. Select File > Open.
b. Select the practice02Sol.jws workspace and click Open. The workspace is in the
<JDeveloper>/jdev/mywork/practice02Sol directory.
2. Create a new JDBC connection.
a. Expand the Connections node in the JDeveloper Connections Navigator pane.
Hint: Click the Connections tab at the bottom of the System Navigator pane.
b. Right-click Database and select New Database Connection from the shortcut menu,
which launches the Database Connection Wizard. Then, click Next.
c. Enter OE in the Connection Name field, and select JDBC as the connection type. You
can choose any name that you want, but the practices and examples all use OE as the
connection name. Then, click Next.
d. Enter the username and password that was given to you by your instructor for your
database, and select Deploy Password. Leave the Role field blank. Then, click Next.
e. Select the thin JDBC driver.
f. Enter the host ID, SID, and port number that was given to you by your instructor. Then,
click Next.
g. Click the Test Connection button to test the connection.
h. Click Finish to save the connection.
3. Start the Application.
a. Click the Applications tab and expand the practice02Sol node.
Hint: The Applications tab is at the bottom of of the System Navigator pane.
b. Expand the ViewController node
c. Expand the Web Content node, right-click the welcome.jsp node, and select the run
option from the context menu.
4. Explore the functionalities of the Application.
a. In the new Browser window, use the links to navigate through the application screens.
b. You can log on by using one of the following usernames and customer IDs:
Welles
101
Pacino
102
Taylor
103
Sutherland
104
MacGraw
105
Hannah
106
c. Experiment with the process of ordering items.
Practice 3-1
If needed, restart JDeveloper 10g, and open the practice03 workspace.
Select File > Open.
Select the practice03.jws workspace, and click Open. The workspace is in the
<JDeveloper>/jdev/mywork/practice03 directory.
1. Create Business Components.
a. Expand the practice03 node in the Applications Navigator.
b. Right-click the Model project, and select the New option.
c. Select Business Components > Business Components from Tables, and click OK.
d. Skip the Welcome screen by clicking Next.
Hint: You can click skip this next time to avoid this introduction page in the future.
e. In step 1 of Create Business Components from the Tables Wizard, specify OE as the
schema owner.
f. Select the following tables to create entities:
CATEGORIES
CUSTOMERS
INVENTORIES
ORDERS
ORDER_ITEMS
PRODUCT_INFORMATION
g. Click Next to accept these entity objects and move to the next step.
h. In step 2 of Create Business Components from the Tables Wizard, select all the tables
to create view objects and click Next.
i. In step 3 of the wizard, select the Application Module check box and specify
SalesAppModule in the name field. Then, click Next to review the business
components creation and click Finish to create the components.
2. Test the Business Components.
a. In the navigator pane, right-click your application module (SalesAppModule) and
select Test from the shortcut menu.
Hint: The application module has an icon that looks like a briefcase with a cog wheel
on it.
b. In the dialog box, verify that the middle-tier server type is set to Local and the JDBC
connection is set to OE, and then click Connect.
c. In the browser, double-click CustomersView1 and browse the customers data.
d. Click the blue up oriented icon (eject button) to see CustomersView1 in a separate
window.
Categories
Customers
Inventories
OrderItems
Orders
ProductInformation
Click OK.
g. Reorganize the layout of the entity objects, and save your work. See the next page for
an example of a suggested layout.
Hint: Reorganize the layout by dragging the objects around to the diagram or by rightclicking on the diagram and selecting one of the automatic layout options.
Practice 4-1
This practice illustrates the various ways to create entity objects.
1. Start JDeveloper 10g, and create a new Application Workspace.
Hint: Start the Application Wizard by selecting File > New from the menu or by selecting
New from the Workspace shortcut menu (right-click the Workspace node).
Select Workspaces > Application Workspace from the New Gallery.
a. In the Application Wizard, change the name of the Application to practice04.
b. Leave the default values for the Directory Name and Application Package Prefix.
c. Make sure that the Application Template is Web Application [Default]. Then, click
OK.
2. Create entity objects from tables.
a. Expand the practice04 node in the Applications Navigator.
b. Right-click the model project, and select the New option.
c. Select Business Components > Business Components from Tables.
d. Make sure that the OE connection is selected in the Project initialization page.
e. In step 1 of the wizard, select the following tables:
CUSTOMERS
ORDERS
ORDER_ITEMS
f. Click Next to accept these objects and move to the next step of the wizard.
g. In step 2, select all the entities and create default view objects for them. You are
creating default views so that you can test the entity objects that you will be working
with in this practice.
h. In step 3, enter SalesAppModule for the name of the default application module.
i. Click Finish when you are done.
3. Create a Business Components diagram.
a. Right-click the model project, and select New.
b. Select Business Components Diagram.
c. Name the diagram Entity Objects.
CATEGORIES
PRODUCT_INFORMATION
CustAddressTyp
SdoGeometry
SdoPointType
Hint: These objects are object type created by default from the table
definitions. You will not use these objects in the application that you are building, so it
is easy and clean to remove them from the entity definition.
5. Add the remaining entity objects to the diagram.
a. In the Applications pane (not the Connections pane), select the remaining entities and
drag them to the diagram:
Customers
Orders
Practice 4-2
To start this practice, restart JDeveloper, if neccesary, open the practice04 workspace, and
open the model project created in practice 4-1.
1. Add a validation rule to validate customers status.
a. Edit the Customers entity object to add a validation rule.
Hint: Edit the entity by double-clicking the entity in the System Navigator.
b. Your new rule is a ListValidator rule that ensures that the Status attribute has one of the
following values:
Platinum
Gold
Silver
Hint: Add a new rule by clicking the Validation node in the Entity Object Editor,
selecting the Status attribute and clicking the New button at the bottom of the window.
Make sure to select ListValidator as the rule.
c. In the Error Message field, enter Status can only be Platinum, Gold or Silver.
d. Click the OK button twice to add the validation.
e. Save your changes.
f. Select the Customers entity in the navigator pane. Note that the new rule is shown
under the Status attribute as a rule.
2. Validate e-mail attributes using a domain object.
Note that you can create the domain from the New Gallery or by using the Component
Palette when using an Entity Objects diagram.
a. Create a domain object called EmailAddressDomain. Refer to the domain slides in
this lesson if you need a reminder of how to do this. Later in the course, you will add
some code that verifies that an attribute is a valid e-mail address.
Hint: To create a domain, right-click the Model node in the workspace, and select New
Domain from the context menu. You can also select Domain from the Component
Palette of the Business Components Diagrammer and click the diagram.
b. Edit the Customers entity, and set the type of the CustEmail attribute to
EmailAddressDomain.
Hint: To edit an entity, double-click the entity in the System Navigator. Click the
Attributes node in the Entity Editor window, then select the Email attribute and change
the type to EmailAddressDomain.
c. Save your changes.
3. Run the Business Components Browser to check your new validation rules. Try to change the
status of a customer to a value that is not in the list of valid values.
Hint: To run the Business Components Browser, right-click the Application Module and
select Test from the context menu.
4. Close the browser when you are done.
Practice 5-1
Open the practice05 application workspace. This application is the starting point for this
practice and includes all the steps that you should have completed so far.
1. Create a business component diagram for view objects.
a. Select the model node in the Applications Navigator, and right-click and select the New
option.
b. In the New Gallery, select Business Components > Business Components Diagram, and
click OK.
c. Name the diagram View Objects and click OK.
2. Create view objects from the navigator pane.
a. Select the entity object Categories in the navigator pane.
b. Right-click to open the context menu.
c. Select the New Default View Object option.
d. Click OK in the Create Default View Object dialog box.
3. Create view objects manually from the Component Palette.
a. Select the View Object in the Component Palette for the View Objects Diagram.
Hint: The Component Palette is usually a window just to the right of the Business
Components Diagrammer.
b. Click the diagram.
c. Change the name to InventoriesView.
Hint: Change the name of the object by clicking the name twice (not double-click), and
then entering the new name.
d. Double-click InventoriesView.
e. Select the Entity Object node.
f. Select Inventories as the available entity object and move it to the Selected window by
using the right arrow (>).
g. Select the Attributes node.
h. Select all the available attributes and move them in the Selected window.
i. Click OK to accept your changes.
4. Create view objects automatically from the Component Palette.
a. Select the view object in the Component Palette for the view objects diagram.
b. Click the diagram.
c. Change the name to ProductInformationView.
d. In the navigator pane, select the ProductInformation entity.
Hint:The navigator pane is the window on the left side of the diagrammer.
e. Drag the ProductInformation entity to the ProductInformationView box.
f. Double-click ProductInformationView to see what properties have been added to the
view object.
Hint: Note that all the attributes have been added to the view object.
CategoriesView
CategoryId
CategoryName
CategoryDescription
CustomersView
CustomerId
CustFirstname
CustLastName
CustEmail
CreditLimit
NlsLanguage
Status
InventoriesView
ProductId
QuantityOnHand
RowId
WarehouseId
OrderItemsView
OrderId
LineItemId
ProductId
UnitPrice
Quantity
DiscountUnitPrice
OrdersView
OrderId
OrderDate
CustomerId
OrderStatus
ProductInformationView
ProductId
ProductName
ProductDescription
CategoryId
ListPrice
Number
Number
Number
String
Number
Practice 5-2
If necessary, restart JDeveloper, open the practice05 workspace and the project model.
1. Add a calculated attribute to the OrderItemsView view object to display the total cost of
each line item. To calculate a line items total, multiply the orderItem quantity with the
discountUnitPrice. It is also useful to see the inventory items name, so you will add code to
display the item name.
a. Edit the OrderItemsView view object and add ProductInformation.Name to the view
objects attribute list. (Add ProductInformation as an entity, and then select
ProductName as an attribute).
Hint: Open the View Object Editor, and select the Entity node in the Editor window.
Select the ProductInformation entity and click the shuttle button to add it to the selected
entity list. Click the Attributes node, select ProductName, and then click the shuttle
button to add it to the attributes list.
b. Add a calculated attribute to the OrderItemsView view object, using the following
information:
The name of the attribute is LineTotal; it should be of type Number. Make sure
that the attribute is always updatable.
The attribute displays the total cost of the line item (use discountUnitPrice).
Use the attribute query expression to calculate the value of LineTotal.
The query should look like the code below:
SELECT OrderItems.ORDER_ID,
OrderItems.LINE_ITEM_ID,
OrderItems.PRODUCT_ID,
OrderItems.UNIT_PRICE,
OrderItems.QUANTITY,
OrderItems.DISCOUNT_UNIT_PRICE,
ProductInformation.PRODUCT_NAME,
ProductInformation.PRODUCT_ID AS PRODUCT_ID1,
OrderItems.QUANTITY * OrderItems.DISCOUNT_UNIT_PRICE as LineTotal
FROM ORDER_ITEMS OrderItems, PRODUCT_INFORMATION ProductInformation
WHERE OrderItems.PRODUCT_ID = ProductInformation.PRODUCT_ID
Practice 6-1
To start this practice, if necessary, restart JDeveloper, open the practice06 workspace, and
open the model project. This project includes all the work that you should have completed to this
point in the course.
1. Enforce your validation rule to be case insensitive.
In practice 4-2, you created a ListValidator that ensures that the Status attribute of the
Customers entity has one of the following values: Platinum, Gold, and Silver. At this
point, your validation rule rejects values such as silver, which are invalid only because
the case is different. So, you need to change your validation rule so that it accepts any
combination of uppercase and lowercase letters.
Note: The resolution of this problem involves adding code to
CustomersImpl.setStatus(). Two possible solutions are:
- In the Entity Object Wizard, enter the list of valid values in uppercase (PLATINUM,
GOLD, and SILVER); in setStatus(), convert the status to uppercase.
- In the Entity Object Wizard, leave the list of valid values as Platinum, Gold, and
Silver; in setStatus(), convert the initial character of the status to uppercase
and the rest of the word to lowercase. This technique will return a value styled in initial
caps, regardless of what the user enters.
a. Click the Customers entity object. In the Structure pane, expand the Sources node,
and double-click the CustomersImpl.java node to view the code.
b. In the Structure pane, locate the setStatus():void method and click it.
c. In the Java Source code, add statements for the case-insensitive validation rule.
Hints: If you cannot remember the exact name of a method that you want to call in your
code, enter the object name followed by ., and wait for a second; JDeveloper will bring up
a list of valid methods to select from. Your code should look like the following.
public void setStatus(String value)
{
String status = value.substring(0,1).toUpperCase() +
value.substring(1).toLowerCase();
setAttributeInternal(STATUS, status);
}
Practice 7-1
Start JDeveloper 10g, and open the practice07 workspace.
1. Create a view object from a SQL statement.
a. Create a new view object named OverstockView that selects all the products in the
Inventory for which the available sum of quantity in all warehouses is greater than 100.
The view uses the inventory and products table.
Hint: Use the expert mode to enter the query. To change the query to expert mode,
click the query node in the editor, then click the expert mode check box. You can now
enter the query shown below.
SELECT ProductInformation.PRODUCT_ID,
ProductInformation.PRODUCT_NAME,
SUM(Inventories.QUANTITY_ON_HAND) QTY
FROM PRODUCT_INFORMATION ProductInformation,
INVENTORIES Inventories
WHERE
ProductInformation.PRODUCT_ID =
Inventories.PRODUCT_ID
GROUP BY ProductInformation.PRODUCT_ID,
ProductInformation.PRODUCT_NAME
HAVING SUM(Inventories.QUANTITY_ON_HAND)>100
b. Create a default application module named SQLBasedViewModule and add the view
OverstockView to it.
Hint: To create a new application module, right-click the model project in your
workspace and select New Application Module from the context menu. On the second
page of the wizard, select OverstockView and add it to the data model.
c. Build and test your application module and view object.
2. In the business, you have customers that have qualified for special discounts. Platinum
customers get a 4% discount on all items, while Gold customers get a 3% discount on all
items. You will recalculate the discountUnitPrice when the quantity is changed.
- To calculate the discount price, you need to retrieve the listPrice of the item, multiply it
by the customers discount and store the result in the discountUnitPrice. Remember that
because this code changes data, not just presentation, the code will go on the
OrderItems entity object.
Hint: The code is listed in its entirety at the end of this practice.
a. If a customer is Platinum, apply an additional 5% discount.
b. If a customer is Gold, apply an additional 3% discount.
Hint: If you need help with the code, it is included at the end of this practice.
c. Build and test your project.
d. Add a print statement at the end of the main() to display a success message when you
successfully make it through the program.
public static void main(String[] args)
{
String
amDef = "model.SQLBasedViewModule";
String
config = "SQLBasedViewModuleLocal";
ApplicationModule am =
Configuration.createRootApplicationModule(amDef,config);
System.out.println("App Module Success");
}
e. Save your changes, and compile and test your program. At this stage, your program
does not pull any data from the database, but it should compile and run without error
and display your success message. This proves that you were able to instantiate the
application module. With that complete, you can begin to add code that will display
data from the Business Components in the SQLBasedView application module.
Oracle JDeveloper 10g: Build Applications with ADF B-20
h. Add code to instantiate the OverStockView object, set its Where clause parameter
to the value of the argument from the command line, and execute the query on the view
object.
ViewObject vo = am.findViewObject("OverStockView1");
vo.setWhereClauseParam(0,howMany);
vo.executeQuery();
i.
i.
Generate the ViewRow interface for your client application. This interface provides the
typesafe methods for your client application. To generate the ViewRow interface, edit
OverstockView and select the Java node. On the Java node page, select the Generate
Java File in the View Row Class section. Select the Generate Java File, Generate
Accessors, and the Expose Accessors to the Client check boxes. This last check box
will generate the ViewRow interface.
Add a loop to display all the rows of the view object displaying the product_id,
product_name, and qty.
Hint: To use typesafe methods, which is highly recommended, you need to edit the
OverStockView object and generate a ViewRow Class. This class holds the typesafe
data access methods (such as getProductId, getProductName). After you create that
class, you can cast the Row object to a OverStockViewRowImpl object to get access to
those methods.
while (vo.hasNext())
{
OverStockViewRowImpl row = (OverStockViewRowImpl)vo.next();
System.out.println("Product Id: " + row.getProductId() );
System.out.println("Product Name: " + row.getProductName());
System.out.println("Quantity in Stock: " + row.getQty());
}
Practice 8-1
Start JDeveloper, and open the practice08 workspace.
It is important to make the business data secure and ensure that all the records comply with the
business logic.
1. Configure the ADF application to use SSO authentication.
a. Close JDeveloper.
b. Open the java.security file in the <JDevHome>\jdk\jre\lib\security folder.
c. Add the following statement at the end of the file:
login.configuration.provider=oracle.security.jazn.spi.LoginConfigFile
Practice 9-1
Start JDeveloper, and open the practice09 workspace.
1. Create a Page Flow Diagram.
a. Open the ViewController node in the Applications Navigator.
b. Double-click the struts-config.xml file located in the Web Content/WEB-INF
folder.
c. Open the Component Palette.
d. Create a diagram as the one below, which includes the following components:
Page:
/welcome
Data Page:
/categories and /products
Page Forward:
/logon
Hint: To create each of the items above, click the correct type in the Component
Palette, which is to the right of the diagram. Then, click anywhere on the diagram
surface.
e. Double-click the welcome page, and using the Design Editor, enter Welcome.
f. Reopen the Page Flow Diagram, and double-click the logon page.
Hint: You can reopen the diagram by clicking the struts-config.xml tab at the
top of the editor window.
g. Click OK on the page name proposal.
h. In the Design Editor, enter Logon.
i. Reopen the Page Flow Diagram and draw a Page Link from welcome to logon.
2. Run the welcome JSP.
a. Go back to the Page Flow Diagram.
b. Right-click on the welcome page and select the Run option from the context menu.
c. You should be able to navigate from welcome to logon and see the corresponding
message on each page.
Practice 10-1
In this practice, use the various tag libraries to create JSP pages. Start JDeveloper, and open the
practice10 workspace.
1. Add a Welcome message to the Welcome page.
a. Double-click the welcome.jsp icon on the Page Flow Diagram.
b. Click the design tab at the bottom to open the Design Editor.
c. Remove the welcome text that you have put in the previous lesson.
d. Select the Struts Bean tag library from the Component Palette.
Hint: The Component Palette is to the right of the Visual Editor window.
e. Double-click the message tag.
f. In the dialog box, look for the key attribute and set its value to welcome.title.
The convention adopted for this course is <JSP_name>.<message_name>.
Note: You can see that there is a list of existing entries in the ApplicationResources
file, so it makes more sense to create the message in ApplicationResources first and
then reference the existing key in the tag. That is what you do from now on.
g. Click OK.
2. Add the message entry in the ApplicationResources file.
a. In the Applications Navigator, locate the ApplicationResources node in
ViewController > Application Sources > View.
b. Open the file and add the following text:
welcome.title=Welcome to our Online Shopping site
c. When you are done, click save or save all on the Windows menu bar.
d. Test the jsp: right-click /welcome on the Struts diagram, and select run. Note the
welcome message.
3. Create the Data Based JSPs categories.
a. Create the following entries in the ApplicationResources file and save your changes.
# Categories
categories.title=Product Categories
# Products
products.title=Product List
Hint: Open the resources file just as you have done in step 2.
b. Display the Page Flow Diagram.
c. Double-click the /categories data page.
d. Accept the page name and select the Edit this page now check box. Click OK.
e. Drag a Struts Bean message tag. Set the key value to categories.title.
f. Open the Data Control Palette.
Hint: The Data Control Palette is a tab on the Component Palette, which is to the right
of the Visual Editor.
g. Expand SalesAppModuleDataControl, and then the CategoriesView1 node.
h. Select CategoriesView1 and set the Drag and Drop As List to Read-Only Table.
i. Drag the view to the Design Editor.
j. Test the jsp: right-click /categories on the Struts diagram, and select run. Remember
that the pages that you are creating must run from within the Struts controller. They
will not run as stand-alone JSPs.
6. Create the logon JSP. Perform the same process that you used for the other pages.
a. Open logon.jsp that you created in an earlier practice, and remove the logon text.
b. Add a Struts HTML error tag and a Struts message bean. Set the message bean key to
logon.title.
c. Add a second Struts bean message, and set its key value to logon.subtitle.
d. Add an HTML table tag, and specify 3 rows 2 columns.
Hint: To add an HTML table, select HTML from the list of available component types
in the Component Palette, and then select table from the list.
e. In the top left cell, add a Struts bean message tag and set the Key value to
logon.lastname.
f. In the same column next row, add a Struts bean message tag, and set the Key value to
logon.customerid.
g. In the top right cell, drag an HTML text field tag. Double-click it. When asked, do not
add a form element. Specify lastName as name.
h. In the same column next row, drag an HTML password tag and set its property to
customerId. When asked, do not add a form element.
8. Modify the applicationResources file to make the link messages more usable.
a. Open the applicationResources file and note that when you added links to the pages,
JDeveloper added entries for those links.
b. Change the values of those links to more helpful messages.
c. Save the file and test the application again.
Practice 11-1
In this practice, you create a form bean to hold logon information. That logon information will be
passed to an action that performs authentication and returns a customer name if the validation
succeeds.
Start JDeveloper, if necessary, and open the practice11 workspace.
1. Create form beans.
a. Open the Page Flow Diagram.
b. In the Structure pane, create a new form bean.
Hint: The Structure pane is usually below the System Navigator. Right-click the Form
Beans node, and select New from the context menu.
c. In the Properties pane, specify logon as the name and set the type to
org.apache.struts.action.DynaActionForm.
Hint: Use the Property Inspector to set these values. Use the Edit button (the button in
the type field) to select the type from the list.
d. In the Structure pane, select the logon bean and create a new Form Property.
Hint: Right-click the logon bean that you just created, and select new Form Property
from the context menu.
e. In the Property Inspector, set the name property to lastName and leave it as a
String.
f. Create a second Form Property for customerId (leave it as a String).
2. Create a new view object that validates the customer logon. This view object will accept two
parameters and query the customers table for a combination of both customerLastName
and customerId.
a. Create a view object. Name it AuthenticateView. Remember to create the view object
in the model project.
b. Select customers as the entity object.
c. Select customerId, custFirstName, and custLastName as the attributes.
d. Add a WHERE clause that compares the upper of custLastName with the upper of a
parameter AND compares customerId with a second parameter.
SELECT Customers.CUSTOMER_ID,
Customers.CUST_FIRST_NAME,
Customers.CUST_LAST_NAME
FROM CUSTOMERS Customers
WHERE upper(Customers.CUST_LAST_NAME)= upper(?)
and Customers.CUSTOMER_ID= ?
e. Make sure to select the Use ? Style parameters check box if you are using the above
syntax.
f. In step 6 of 6, select the Generate Java File option for the View Row Class.
g. Click Finish to validate.
h. Add the view to SalesAppModule. Remove 1 from the instance name.
Hint: To edit the application module, right-click SalesAppModule in the System
Navigator and select edit SalesAppModule, or double-click the application module.
e. Remove the link to the categories page that you added in an earlier practice.
f. Right-click the /logon page on the Page Flow Diagram, and choose the Refresh
Diagram from Page option. A page link should appear between l/ogon and
/authenticateUser.
9. Run the application starting at the welcome page. Try to log on with the following values of
CustomerLastName and CustomerId:
Welles 101
Pacino 102
Taylor 103
10. You will enhance this validation in a later practice.
Practice 12-1
Adding features to data pages.
Start JDeveloper, if necessary, and open the practice12 workspace.
1. In this step, you add navigation operations to the categories page. The buttons will enable
the user to navigate forward or backward through sets of category rows.
a. Open the categories data page.
Hint: Double-click the /categories page in the Page Flow Diagram.
b. In the Data Control pane, open the SalesAppModuleDataControl node and expand the
CategoriesView node, and then the Operations node.
c. Select the Previous Set item, and drag it to the Design Editor following the last object.
If prompted with an Add Form Element Confirmation dialog box, answer Yes.
d. Perform the same steps and add the Next Set operation and drag it next to the Previous
Set button.
Hint: Your page should look like the following.
e. You need to include the data table inside the form tag that you just added. Go to the
Source tab, find the <form> tag, and move it to just above the <table> tag.
f. Next, set the action property of the form to categories.do.
Hint: From the Visual Editor, right-click inside the form tag, and select the Select
Form tag from the context menu. After the form tag is selected, use the Property
Inspector to change the action property to categories.do. When you are done,
your code should look like the following.
Practice 12-1
Categories.jsp
<form action="categories.do">
<table border="1" width="100%">
<tr>
<th>
<c:out value="${bindings.CategoriesView1.labels['CategoryName']}"/>
</th>
<th>
<c:out value="${bindings.CategoriesView1.labels
['CategoryDescription']}"/>
</th>
<th>
<c:out value="${bindings.CategoriesView1.labels['CategoryId']}"/>
</th>
</tr>
<c:forEach var="Row" items="${bindings.CategoriesView1.rangeSet}">
<tr>
<td>
<a href="categories.do?event=setCurrentRowWithKey&Arg0=
<c:out value='${Row.rowKeyStr}' />">
<c:out value="${Row['CategoryName']}"/></a></td>
<td>
<c:out value="${Row['CategoryDescription']}"/>
</td>
<td>
<c:out value="${Row['CategoryId']}"/>
</td>
</tr>
</c:forEach>
</table>
<input type="submit" name="event_PreviousSet" value="PreviousSet"
<c:out value="${bindings.PreviousSet.enabledString}" />/>
<input type="submit" name="event_NextSet" value="NextSet"
<c:out value="${bindings.NextSet.enabledString}" />/>
</form>
Practice 12-1
2. Modify the iterator so that the page does not display all the items at one time. This will make
the pages more user-friendly. If the users do not see the category they are looking for, they
can click one of the buttons to see the next set of records rather than having to scroll to see
all the categories.
a. In the Applications Navigator, click the categories.jsp node.
b. In the Structure pane, click the UIModel tab, which is the second tab at the top of the
Structure pane.
c. Click CategoriesViewIterator, and set the Range Size value to 5 in the Property
Inspector. This will restrict the number of categories displayed on a page to 5.
3. Add navigation operations to the products page.
a. Open the products data page.
b. Within the CategoriesView node, expand the ProductInformationView node, then the
Operations node and add Previous Set and Next Set items as you did for the categories
page. Do not forget to move the <form> tag and set the action property to
products.do.
4. Modify the products iterator to display 5 rows just like you did for the categories iterator.
5. Clean up the unnecessary columns from both pages.
a. In the table created for the view, select the first top left cell, right-click, select Table
from the context menu and select the Delete Column option.
b. This will remove the current_row column from the table.
e. Move the <a href tag around to include the category name.
<a ref="categories.do?event=setCurrentRowWithKey&Arg0=
<c:out value='${Row.rowKeyStr}' />">
<c:out value="${Row.CategoryName}"/></a>
e. The cartTotal() method returns the total of all the items in the cart. To do this, it
creates a rowSetIterator of the shoppingCart and iterates through it,
summing the extendedTotal attributes as it does. At the end of the
RowSetIterator, it returns the total.
e. Click OK. You are now ready to use this snippet wherever you need.
f. From the Component Palette, select code snippets. In the Design Editor, place your
cursor just before the productId value in the read-only table. Now click the a href
item in the Component Palette. This adds your code snippet to the page.
g. Find the code in the Source Editor and change it for your specific application by
replacing myPage, myEvent, myArg, and myValue. Your code should look like:
<a href="products.do?event=addToCart&prodId=<c:out
value="${Row.ProductId}" />">
<c:out value="${Row['ProductId']}"/></a>
h. Add a forward from the products page to the shoppingCart page. Name the forward
viewCart.
Hint: Select the Struts Page Flow elements from the Component Palette drop-down list.
Click the forward icon, and then click the products page, followed by the shoppingCart
page.
13. In the Visual Editor on the products page, add an href that calls the forward to the
shoppingCart. The code should look like the following code (you can use the snippet again):
<a href="products.do?event=viewCart">View your Cart </a>
Practice 13-1
In this practice, you enhance the views and create a new view.
Start JDeveloper, if necessary, and open the practice13 workspace.
1. Enhance the view objects to make the the UI more user-friendly.
a. Edit the CreditLimit attribute in the CustomersView. On the Control Hints tabbed
page, set the format type to currency and format to $0000.00.
b. Edit the UnitPrice and DiscountUnitPrice attributes in OrderItemsView. Set the format
type to currency and format to $0000.00.
c. Edit the OrderDate attribute in OrdersView. Set the format type to Simple Date and
format to yyyy-mm-dd.
d. Edit the ListPrice attribute in ProductInformationView. Set the format type to
currency and format to $0000.00.
e. Edit the ListPrice and ExtendedTotal attributes in ShoppingCartView. Set the format
type to currency and the format to $0000.00.
2. Add a validator for input fields by adding the validator plug-in to the Strutsconfig.xml file.
a. Open the Page Flow Diagram.
b. In the Structure pane, right-click the the top-level Struts Config node and choose New
> Plug In from the context menu. This will create a new plug-in node in the structure.
c. Select the new plug-in node and switch to the Property Inspector.
d. Set the className property for the plug-in to
org.apache.struts.validator.ValidatorPlugIn.
e. Now with the plug-in node still selected in the Structure pane bring up the context
menu and choose New > Set Property. This will create a child node under the plug-in
labeled as <set-property>.
f. Select the new <set-property> entry and switch to the Property Inspector.
g. Set the property property for this <set-property> entry in the inspector to pathnames.
h. Set the value property to the following (this can be changed to suit your application):
/WEB-INF/validator/validator-rules.xml,/WEBINF/validator/validations.xml.
i. The /WEB-INF/validator directory already has a copy of the Validator rules file.
That file has been copied for you from the basic version supplied with JDeveloper. The
file is delivered in %JDEV_HOME%/jakarta-struts/lib/validatorrules.xml.
e. Run the logon page and provide some incorrect values to test Last Name and Customer
ID validation.
f. When you are done testing, close your browser.
Practice 14-1
At this point, the pages that are built are displayed by using a default presentation, which is not
bad, but probably not good enough for an enterprise application. In this practice, you add a few
things that make the pages more user-friendly.
Start JDeveloper, if necessary, and open the practice14 workspace.
1. Create a heading page.
a. In the Page Flow Diagram, create a JSP page and name it /heading.jsp
b. Add Welcome to the top of the page. Use a messageBean for consistency.
c. Next add a JSTL out tag to get sessionScope.customerName.
${sessionScope.customerName}
Hint: You access the JSTL components from the Component Palette. Select JSTL as
the component type from the drop-down list. Select the c:out tag and add it to the
page. Enter the code above in the value property in the dialog box.
d. In the Component Palette, select CSS from the list and drag the JDeveloper CSS to the
page.
2. Include the heading page in all pages.
a. Select the logon page.
b. Select the JSP jsp:include tag and drag it to the top of the page.
c. Use the Browse button to find and select the heading page.
d. Repeat the operation for the categories, products, and shoppingCart pages.
3. Update the CSS to make your read-only tables more readable.
a. Select the CSS | jdeveloper.css node in the Web Content folder.
b. In the Structure pane, select the TH node.
c. In the Property Inspector, set the background-color value to #336699 or a color of your
choice.
d. Set the color to White.
e. Set the font-style key to italic, font-weight to bold, and text-align to center.
4. Update the categories page to use messageBeans for the headings.
a. Open the ApplicationResources file and add the following entries. Make sure to save
the file when you are done:
category.id= Category Id
category.name= Name
category.description= Description
b. Open the categories page in the Visual Editor.
c. If there is a currency column in the read-only table, select it, and
remove it from the table.(Right-click | table | Delete Column).
d. It there is no title message bean, add it. Set the title message bean style to Heading1
(H1). Make sure to exclude the jsp:include and error tags from the H1 style.
Practice 15-1
In this practice, you will change the logon routine to use JAZN security authorization.
In earlier practices, you used a method in the SalesAppModuleImpl class to find customer
information based on a logon page. The method accepted a username and password, performed a
lookup in the Customers table, and returned a concatenated username. You then used that name to
display in the heading for each of the pages in your application. Now you will use another method
that gets the user ID from JAZN.
Start JDeveloper, if necessary, and open the practice15 workspace.
1. First, you will configure the application to use JAZN security for authentication.
a. Right-click the web.xml file and select properties to edit the deployment descriptor.
b. Select the Login Configuration node, and then select HTTP Basic Authentication for
the authentication type.
c. Add a new security role by selecting the Security Roles node. Click the add button and
enter users as a new role.
d. Next add a security constraint by clicking the Security Constraint node, and clicking the
New button at the bottom of the navigator.
e. Add a new Web resource and name it SalesApp.
f. Add a URL pattern, and set the value to /.
g. Next, click the Authorization tab and click users to authenticate that group to your
application.
h. Test the application. You can right-click on any page on the pageflow diagram and
select run. Because the entire application is protected, anywhere you choose to start
will require a JAZN logon. The valid user IDs are user with the password of 456,
SCOTT with a password of TIGER, and anonymous with any character as a
password. Try to use an invalid ID or password.
2. Now that you have JAZN working to authenticate users, add an action that will use the JAZN
authenticated user ID to look up customer information and store it in
sessionScope.customerName.
You will add a new path to the categories page, which will use this DataAction. In reality,
you may replace the current authenticateUser DataAction with this new one, but you should
be able to compare the two techniques.
a. Add a DataAction to the Page Flow Diagram and name it authenticateUserJAZN.
You can do this on the diagram or change the path in the Property Inspector.
b. Expand the SalesAppModule node in the Data Control Palette and drag the
findCustomerJAZN method to the new DataAction.
c. Select the authenticateUserJAZN node in the Structure pane and change the
resultLocation value to {sessionScope.customerName}. This will put the results of the
findCustomerJAZN method into the session variable customerName.
d. Add a Page Link from the Welcome.jsp page to the new DataAction.
e. Add a forward from the DataAction to the categories page.
3. Add users to the JAZN definition and test the application.
a. Add two new JAZN users. From the JDeveloper menu, select Run | Terminate |
Embedded OC4J Server, if the option is available. Next, select Tools | Embedded OC4J
Server Preferences. Under the Global node, expand the Authentication (JAZN) node.
Expand Realms | jazn.com and click the Users node. Add two users: user 101 with a
password of 101, and user 102 with a password of 102. Select the Roles node and click
users in the Roles pane. Click the Member Users tab and move users 101 and 102 to
the selected pane. Click OK.
Oracle JDeveloper 10g: Build Applications with ADF B-53
Practice 15-1
b. Right-click the welcome.jsp page and select Run from the context menu. When
prompted, enter a user ID and password. The valid user IDs are 101 and 102. The
passwords are the same as the user IDs.
c. Click the authenticateUserJAZN link. This is the new link that you just added.
d. Note that you are directed to the categories page and that the username is displayed at
the top of the page.
e. Experiment with other user IDs, including invalid IDs.
f. Close the application when you have done testing.
Tab Destination
Customers
Products
Details
Destination URL
Image Location
Cart
..\public_html\images\cart.gif
Help
..\public_html\images\help.gif
Logon
..\public_html\images\login.gif
Practice 17-1
The purpose of this practice is to deploy a Struts application to OC4J. You will be manually
deploying the application created in practice 14 to a local OC4J server. The OC4J server will
actually be that which is installed with JDeveloper, but the deployment steps are the same for a
production deployment.
Start JDeveloper, and open the practice17 workspace.
1. The ADF framework requires version 1.4 of the Java run time. To make sure that this is the
default version on your machine, run java version from a command prompt. If the
version is not 1.4, change your path statement to ensure that the correct version is used. The
1.4 Java run time is delivered with JDeveloper and is the directory
<Jdev_Home>/jdk/bin.
2. First, install the OC4J server.
a. Open a command prompt, and navigate to the <JDEV_Home>\j2ee\home
directory. This is where the OC4J server is installed.
b. Type java -jar oc4j.jar install at the prompt to start the install of the
OC4J server.
c. Specify a password that you want to use (admin). You will need this password in the
next few steps.
d. Confirm you password.
3. Next, start the OC4J server.
a. Open a command prompt and navigate to the <JDEV_Home>\j2ee\home directory.
This is where the OC4J server is installed.
b. Type java -jar oc4j.jar at the prompt to start the OC4J server.
c. The server will automatically deploy any .war files that were included in the
deployment directories at install, and when finished will display Oracle
Application Server Containers for J2EE 10g (9.0.4.0.0)
initialized Oracle9iAS (9.0.2.0.0) Containers for J2EE
initialized.
4. Next, create a connection to the OC4J server.
a. Click the Connections tab on the navigator pane. Right-click Application Server and
select New Application Server Connection from the context menu.
b. Name the new connection OC4J. Select the StandaloneOC4J type and click Next.
c. Supply the username and password for the OC4J Connectionthe admin password is
the one that you have specified at install. Select the Deploy Password check box, and
then click Next to continue.
d. Accept the default ormi mappings for the server, and click Next.
e. Test the connection to ensure that the server is running and the username and password
are valid.
5. Set the Welcome.jsp as the default run target for the application.
a. Open the Page Flow Diagram for the application.
b. Right-click welcome.jsp on the diagram.
c. Choose Set as Default Run Target from the context menu.
6. Now create a deployment profile for the application.
a. Right-click the ViewController node, and select New from the context menu.
b. Create a New deployment profile by using the war file.
c. Specify shoppingApp as the deployment profile name.
d. Click OK to close the Deployment Profile Wizard.
Oracle JDeveloper 10g: Build Applications with ADF B-58