In this lesson, you will create a Java application and expose
it as a portlet in the Portal Repository. You will add this Java portlet on
a Portal page. You will learn about the different show modes supported by the
portlet. You will use the Oracle PDK Java Portlet Wizard, a plug-in for Oracle
JDeveloper 10g (9.0.5.1),
to create this portlet.
The Oracle Application Server Portal
Developer Kit (OracleAS PDK) is a powerful framework to create portlets,
which are the reusable, pluggable Web components that display portions of Web
content. When creating a portlet, there are two basic areas of work: creating
the business logic implementing the desired functionality, and wrapping this
business logic into the OracleAS PDK framework (in other words, using the APIs
described in the OracleAS PDK to code your portlet).
The Oracle PDK Java Portlet Wizard reduces the amount of
work required for wrapping your business logic, so you can concentrate on implementing
the desired functionality. Using the Oracle PDK Java Portlet Wizard dramatically
increases your flexibility and productivity when developing portlets. The Oracle
PDK Java Portlet Wizard, which is fully integrated with Oracle JDeveloper, generates
source files along with all the necessary configuration files for your portlet.
JDeveloper also supports testing, debugging, and deploying portlets. JDeveloper
is shipped with an integrated stand-alone Oracle Container For Java
(OC4J), which you can use as a test environment for your portlets.
You need to have a good understanding of Java servlets
and JavaServer Pages. In addition, you should be familiar with J2EE development
using an Integrated Development Environment (IDE) such as Oracle JDeveloper.
To complete this lesson, you must have installed Oracle
JDeveloper 10g (9.0.5.1)
and the Portal Extension for Oracle JDeveloper.
You can download and install Oracle JDeveloper 10g
(9.0.5) from http://otn.oracle.com/software/products/jdev/index.html.
The location of your Oracle JDeveloper installation will be referred to as <jdev_install>.
The Portal Extension for Oracle JDeveloper provides two wizards:
Java Portlet Wizard and Oracle PDK Java Portlet Wizard. Using the Java Portlet
wizard, you can build portlets based on standards, such as WSRP and JSR 168.
The Oracle PDK Java Portlet wizard enables you to build portlets based on the
OracleAS PDK APIs. You can download and install the Portal Extension for Oracle
JDeveloper from Oracle
JDeveloper 10g -
Extensions Exchange. Alternatively, you can download the portal-addin-install.jar
file from the <portal_unzip>\portalOBE\wizard folder and follow
the guidelines in <portal_unzip>\portalOBE\wizard\jdev.addin.install.guide.html
to install the Portal Extension for Oracle JDeveloper.
You can use the Oracle PDK Java Portlet Wizard
to build Java portlets for OracleAS Portal. The Oracle PDK Java Portlet Wizard
also enables to you package and deploy your Web provider. Using the wizard,
you can create, test, and deploy Java portlets from within Oracle JDeveloper.
You can also use the Oracle PDK Java Portlet Wizard to create a portlet and
portlet provider for registration with OracleAS Portal.
The portlet content appearing on a portal page
is usually generated by several portlet programs, which are also called portlet
renderers. Standard portlet renderers can be of four types: Java Server Pages,
Java servlets, static HTML pages, and Java classes. In this lesson, you will
create the portlet content by using a JSP file and specify parameters for your
Java portlet. You test the Java application and register the Web provider with
OracleAS Portal. Then, you add the portlet to your portal page and map the page
parameters to your Java portlet parameter. Finally, you can see your Java portlet
in action.
You will now open the JDeveloper IDE to create
a JSP page by using the Oracle PDK Java Portlet Wizard. Then, you will register
the JSP page as a portlet that you run within OracleAS Portal.
1.
To start JDeveloper on Windows, run
the <jdev_install>\jdev\bin\jdevw.exe file.
To start JDeveloper on other platforms, run the <jdev_install>/jdev/bin/jdev
file.
2.
Select File
> New from JDeveloper's menu.
3.
The New
Gallery window is displayed.
In the General Category, select the Workspaces option
in the left panel and select the Workspace item in
the right panel.
Note: In JDeveloper, you use workspaces
to organize the projects you use while developing your programs. You use
projects to organize the related files that together make up an application.
You must first create a workspace and a project to hold the files that
you create in JDeveloper.
4.
Click OK.
5.
In the Create
Workspace dialog box, ensure that the Add a New Empty Project
check box is selected, and accept all default values.
6.
Click OK.
7.
In the Create
Project dialog box, accept all default values and click OK.
8.
Right-click the Project1
in the System-Navigator window and select New...
from the shortcut menu.
Note: JDeveloper's
New Gallery is the launching point for creating objects, such as applications,
projects, classes, and JSPs. Most items selected in the New
Gallery window invoke a wizard to help step you through the
creation process.
9.
Expand the Web Tier
node.
10.
Select Portlets.
11.
In the right panel
of the NewGallery window, select Oracle
PDK Java Portlet.
12.
Click OK.
13.
On the Welcome
page of the Oracle PDK Java Portlet Wizard, click Next.
The Oracle PDK Java Portlet Wizard guides you through
the steps that are required to create the starting code for your portlet.
14.
In Step 1 of the
wizard, you specify the basic information about your new Java portlet.
Specify the following details for the respective fields:
Portlet Name = MyJDevPortlet
Display Name = My JDeveloper Portlet
You can leave the other fields with their default
values.
15.
Click Next.
16.
In Step 2 of the wizard, you provide information about the portlet's
show modes. A portlet's show mode, also called a display mode, is an
area of functionality that a portlet provides. Portlets provide different
functionalities by implementing a number of show modes, such as Help,
Edit, About, Preview, and so on.
Specify the following details for the respective fields:
Show page = Selected
This is also called the Shared screen
mode. The portlet shares the portal page with other portlets.
Implementation style = JSP
The portlet source files can be of various types.
They can be implemented as JSPs, Java servlets, HTML, or Java classes.
You can use these files as starting points for your portlet.
File name = MyJDevPortletShowPage.jsp
Show details page = Selected
Implementation style = JSP
File name = MyJDevPortletShowDetailsPage.jsp
In the Show details mode, the entire
browser window is dedicated to this particular portlet. A portlet
uses the Show details mode to show more details than it can show when
sharing a page with other portlets. You can access the Show details
mode of the portlet by clicking the portlettitle.
Click Next.
17.
In Step 3 of the wizard,
you specify the customization support required by your portlet.
Specify the following details for the respective fields:
Edit page = Selected
Implementation style = JSP
File name = MyJDevPortletEditPage.jsp
The Edit mode enables end users
to customize the portlet. The Edit mode usually displays an HTML
form that your users can use to personalize the behavior of the
portlet. This mode is accessible by clicking the Customize
link on the portlet header.
Edit Defaults page = Deselected
The Edit defaults mode enables
you to customize the default behavior of the portlet instance on
the page. This mode is available only for users with Edit
page privileges.
Click Next.
18.
In Step 4 of the wizard,
you specify the other functions that you want your portlet to provide.
Specify the following details for the respective fields:
Help page = Selected
Implementation style = HTML
File name = MyJDevPortletHelpPage.jsp
The portlet uses the Help mode
to display information about its functionality and usage. The Help
mode is available from the Help link on the portlet
banner. Use the Help mode to describe the features and how to get
the most out of them.
About page = Selected
Implementation style = HTML
File name = MyJDevPortletAboutPage.jsp
Portlets can use the About mode
to display the copyright, version, and author of the portlet. Portlets
that require registration can link to Web sites or display contact
information from this mode as well.
Click Next.
19.
In Step 5 of the wizard, you can specify your portlet's public portlet
parameters. You will create an input parameter for the portlet to see
how easy it is to map page parameters to public portlet parameters in
the Portal page, just as was done in the Building
Portlets Declaratively lesson.
Click Add.
20.
In the Name field,
enter MyDept.
21.
In the Display Name
field, enter My Department.
22.
In the Description
field, enter: This parameter
was created in the JDeveloper portlet wizard and accepts a value into
the portlet from the Portal page.
23.
Click Next.
24.
In Step 6 of the wizard,
you can specify events that the portlet can raise and parameters that
should be set for each event. You do not need to raise any events in this
lesson.
Click Next.
25.
In Step 7 of the wizard, you specify the information for the portlet
provider.
Specify the following details for the respective fields:
Provider name =<YourName>JDevProvider
Generate deployment properties file = Selected
Generate XML entries = Selected
Generate index JSP = Selected
The Oracle PDK Java Portlet Wizard creates the necessary configuration
files for your provider and Web application: the web.xml, the
provider.xml, and the .properties files. In
general, you do not need to make any changes to the configuration files
that are generated by the Oracle PDK Java Portlet Wizard.
Note: The serviceid.properties
file explicitly contains the configuration information for your provider
definition file, such as the location and name of the provider definition
file, or whether the provider test page is enabled or not. The
_default.properties file specifies the deployment properties
for providers that are registered at the servlet URL, and for which
no identifying service ID has been specified.
26.
Click Finish.
27.
In the System-Navigator window, you now see the files
that were generated by the Oracle PDK Java Portlet Wizard.
Double-click the provider.xml file in the System-Navigator
window.
28.
The provider.xml
file, also called the provider definition file, describes
the relationship between the provider and its portlets. You can find
the portlet's name, title, and description defined in this file.
In addition, you can find out which files are responsible
for rendering the portlet's Help, About,
and Edit show modes.
29.
Double-click the web.xml file in the System-Navigator
window.
The web.xml file enables you to configure the deployment parameters of
Web applications. The provider adapter is a servlet and it is configured
using the web.xml file. In addition, you can specify URL mapping for servlets
and JSPs in the web.xml file. The web.xml file is included in the Web
Application Archive (WAR) file.
Now that you have created the default implementation, you
need to replace or extend the sample code with your business logic to implement
the functionality you want the portlet to perform. In this lesson, you will
modify the JSP file created by the wizard.
1.
In the System-Navigator
window, double-click the MyJdevPortletShowPage.jsp file.
2.
You can see the page in
the Design view. Here you preview the user interface
of the portlet. You can use HTML and the Portal JSP tags to modify the
portlet functionality.
You need to switch to the Code view so that you can
edit the JSP code. Now, click the Source tab at the bottom
of the frame. You can see the page in the Code view.
3.
Locate the following code:
<P>Hello
<%= pReq.getUser().getName() %>.</P>
<P>This is the <b><i>Show</i></b> render
mode!</P>
In order to use the Java portlet in OracleAS Portal, the Java
2 Platform, Enterprise Edition (J2EE) application must first be deployed to
a Oracle Application Server Containers for J2EE (OC4J). The J2EE specification
requires you to package your application files into an Enterprise Application
Archive (EAR) file. JDeveloper enables you to easily package your application
files into an EAR file and deploy them on the application server. OC4J, which
is integrated with JDeveloper, is suited for development purposes, not for production.
Test the provider from JDeveloper to know whether it is accessible.
JDeveloper creates an index.jsp page that lists all the providers
that reside in your Web application with hyperlinks. You can test your provider
by clicking the hyperlink.
In this lesson, you use OC4J, which is integrated with JDeveloper,
to simplify the Web provider deployment.
1.
In the System-Navigator
window, click the index.jsp file.
2.
In the Menu bar, select
the Run >Run index.jsp menu option.
This file gives you all the information you need
in order to register your provider in Portal. Ensure that JDeveloper
is running so that OC4J remains available.
3.
Next, the application must
be registered with Portal so that Portal can locate and execute the
portlet.
Copy the Registration URL from the OracleAS Portlet Application
Test Page window. Use this URL to register your provider with Portal.
Provider registration is the process by which OracleAS
Portal is informed about how the provider can be accessed. Providers are
registered through the OracleAS Portal Web user interface.
4.
Access your Portal window
now.
Click the Navigator link at the top right of the window.
5.
Click the Providers
tab.
6.
Click the Registered Providers
link.
7.
Click the Register New...
Provider link.
8.
Provide the following details
for the respective fields to specify the provider Information:
Name = <YourName>jdevprovider
Display Name = <YourName>
JDeveloper Provider
Timeout = 20 seconds
Timeout Message = <YourName>
JDeveloper Provider timed out after 20 seconds
Implementation Style = Web
Click Next.
9.
The portal and the provider communicate with each other over HTTP. Before
using the provider and its portlets, you must tell the portal through
which URL the provider is accessible. This information is provided when
you register the Web provider.
In the URL field, specify the URL for the Web provider.
Paste the Registration URL copied from the
index.jsp page that you executed from JDeveloper.
For example, http://152.69.214.208:8988/Workspace1-Project1-context-root/providers/.
Enter the <Service
Name> from the index.jsp page
that you executed from JDeveloper. For example, umajdevprovider.
Now that the portlet provider is registered, it will be displayed
in the Portlet Repository with its portlets, like all other
portlets and providers. You will now add the Java portlet to a portal page.
1.
Click the Page Groups
tab.
2.
Your path should be Path: Page Groups
> <YourName> Oracle By Example > Pages.
Click the Edit link to the right of the <YourName>
OBE Home Page link.
3.
Ensure that the HR
tab is selected. Click the Add Portlet
icon to add a portlet to the HR tab.
4.
In the Portlet Repository,
click the Portlet Staging Area link.
5.
Click the <YourName>
JDeveloper Provider link.
6.
ClicktheMy JDeveloper Portlet link to move over to the selected
portlet area.
Currently, the Java portlet has no value set for the My
Department parameter. In the Building
Portlets Declaratively lesson, you configured the pie chart OmniPortlet
(using CSV data source) to raise an event when a pie slice is clicked. The portlet
responds to this event and sends the department number to the page on which
the portlet is displayed. You want the Java portlet to display the appropriate
department number when the user clicks a specific slice of the pie displayed
in another portlet. To do this, you set a value using a page parameter and map
this page parameter to the portlet parameter.
1.
Click the Page Properties
link.
2.
Click the Parameters
tab.
3.
In the Portlet Parameter
Values section, click the HR : MyJDeveloper Portlet link.
4.
In the Portlet Parameter
section, select Page Parameter from the list.
5.
Select dept from the
second list.
6.
Click OK.
7.
Click the ViewPage link at the top
to preview the page.
Notice that the value for the My Department
parameter is now displayed. The Java portlet refreshes when different
pie slices are clicked.
In this lesson, you learned to create a Java application and
expose it as a portlet in the Portal Repository. You added the Java portlet
on a Portal page and enabled parameters to it. You also learned how to use the
Oracle PDK Java Portlet Wizard to implement the different portlet show modes.
You learned about the configuration files involved in the deployment process,
as well as how the Oracle PDK Java Portlet Wizard simplifies the portlet development
and deployment process. Thank you for completing this OracleAS Portal Oracle
by Example.
For more information about OracleAS Portal, please visit