0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; } obj.visibility=v; } } //Define function to show one layer and hide others: function show(whichLayer) { if(layerDisp) { showHide(layerDisp,'','hide'); } showHide(whichLayer,'','show'); layerDisp = whichLayer; } //Define function to keep score and display feedback: function Engine(question, answer, layerSuffix) { if (answer != ans[question]) { show('incorrect'+layerSuffix); } else { if (!done[question]) { score++; } show('correct'+layerSuffix); } done[question] = -1; } //Define function to verify answer for checkbox: function checkAnswer(question, whichform, whichbox) { var checkTotal = 0; with (whichform) { for (i = 0; i < whichbox.length; i++) { if (whichbox[i].checked == true) { checkTotal = checkTotal + eval(whichbox[i].value); } } } Engine(question,checkTotal,question*10); } //Define function to show correct answer for checkbox: function showAnswer(question, whichform, whichbox) { var residue = ans[question]; var currAnswer = 1; if(layerDisp) { showHide(layerDisp,'','hide'); } with (whichform) { for (i = 0; i < whichbox.length; i++) { if ((residue>0) && (residue%(currAnswer*2)==currAnswer)){ whichbox[i].checked = true; residue-=currAnswer; } else { whichbox[i].checked = false; } currAnswer*=2; } } } //Define function to init a form function clearForm(form) { //Set all checkboxes and radio buttons on form to unchecked: for (xx=0; xx < form.elements.length; xx++) { if (form.elements[xx].type == 'checkbox' | form.elements[xx].type == 'radio') { form.elements[xx].checked = false; } } } //Define function to init all forms on reload: function InitForm() { clearForm(document.form1) clearForm(document.form2) clearForm(document.form3) } // End --> function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i

Building Portlets Programmatically

Purpose

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.

Topics

This module covers the following topics:

 Overview
 Prerequisites
 Using the Oracle PDK Java Portlet Wizard
 Modifying the Portlet
 Registering the Web Provider
 Adding the Portlet to Your Portal Page
 Mapping a Portlet Parameter to a Page Parameter

Viewing Screenshots

Move your mouse over this icon to see all images on the page Place the cursor on this icon to display all screenshots. You can also place the cursor on each icon to see only the screenshot associated with it.

Overview

Back to Topic List

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.

Prerequisites

Back to Topic List

In order for this lesson to work successfully, you need to have performed the following:

1. Completed the Installing the Oracle Application Server 10g Infrastructure lesson
2. Completed the Installing the Oracle Application Server 10g Portal and Wireless lesson
3. Downloaded portalOBE.zip and unzipped it into your working directory
4. Completed the Building the Portal Site lesson
5. Completed the Publishing and Searching Content lesson

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.

Using the Oracle PDK Java Portlet Wizard

Back to Topic List

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.

Move your mouse over this icon to see the image

2. Select File > New from JDeveloper's menu.

Move your mouse over this icon to see the image

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.

 

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

5. In the Create Workspace dialog box, ensure that the Add a New Empty Project check box is selected, and accept all default values.

Move your mouse over this icon to see the image

6. Click OK.

Move your mouse over this icon to see the image

7. In the Create Project dialog box, accept all default values and click OK.

Move your mouse over this icon to see the image

8. Right-click the Project1 in the System-Navigator window and select New... from the shortcut menu.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

10. Select Portlets.

Move your mouse over this icon to see the image

11. In the right panel of the New Gallery window, select Oracle PDK Java Portlet.

Move your mouse over this icon to see the image

12. Click OK.

Move your mouse over this icon to see the image

13. On the Welcome page of the Oracle PDK Java Portlet Wizard, click Next.

Move your mouse over this icon to see the image

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

Move your mouse over this icon to see the image

You can leave the other fields with their default values.

15. Click Next.

Move your mouse over this icon to see the image

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 portlet title.

Click Next.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

20. In the Name field, enter MyDept .

Move your mouse over this icon to see the image

21. In the Display Name field, enter My Department .

Move your mouse over this icon to see the image

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 .

Move your mouse over this icon to see the image

23. Click Next.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

In addition, you can find out which files are responsible for rendering the portlet's Help, About, and Edit show modes.

Move your mouse over this icon to see the image

29.

Double-click the web.xm l 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.

Move your mouse over this icon to see the image

Modifying the Portlet

Back to Topic List

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

3. Locate the following code:

<P>Hello <%= pReq.getUser().getName() %>.</P>
<P>This is the <b><i>Show</i></b> render mode!</P>

<%
ParameterDefinition[] params =
pReq.getPortletDefinition().getInputParameters();
%>

<p>This portlet's input parameters are...</p>

...

And change it to:

<P>Hello <b><%= pReq.getUser().getName() %>.</b> The department is: </P>

<%
ParameterDefinition[] params =
pReq.getPortletDefinition().getInputParameters();
%>

Move your mouse over this icon to see the image

If the user accessing the page on which this portlet resides is PORTAL, the portlet content generated by this JSP page will be:

Hello PORTAL . The department is:

Name                 Value

MyDept         < Department Value>

4. Now, switch to the Design view so that you can see the changes you made. Click the Design tab at the bottom of the frame.

Move your mouse over this icon to see the image

Check whether your changes are reflected.

Move your mouse over this icon to see the image

5. Click the Save All icon on the toolbar.

Move your mouse over this icon to see the image

You can use JDeveloper to create a fully customizable JSP to deploy as a portlet.

6. Click the Make icon on the toolbar to ensure that all code compiles correctly.

Move your mouse over this icon to see the image

Registering the Web Provider

Back to Topic List

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.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

5. Click the Providers tab.

Move your mouse over this icon to see the image

6. Click the Registered Providers link.

Move your mouse over this icon to see the image

7. Click the Register New... Provider link.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

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.

It should resemble the following:

http://machineName:portnumber/Workspace1-Project1-context-root/providers/<YourName>JDevProvider

For example, http://152.69.214.208:8988/Workspace1-Project1-context-root/providers/umajdevprovider.

Move your mouse over this icon to see the image

Click Finish.

Move your mouse over this icon to see the image

10. You should receive a message saying your registration was successful. Click OK.

Move your mouse over this icon to see the image

Adding the Portlet to Your Portal Page

Back to Topic List

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.

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

3. Ensure that the HR tab is selected. Click the Add Portlet  icon to add a portlet to the HR tab.

Move your mouse over this icon to see the image

4. In the Portlet Repository, click the Portlet Staging Area link.

Move your mouse over this icon to see the image

5. Click the < YourName> JDeveloper Provider link.

Move your mouse over this icon to see the image

6. Click the My JDeveloper Portlet link to move over to the selected portlet area.

Move your mouse over this icon to see the image

7. Click OK. The portlet is added to your page.

Move your mouse over this icon to see the image

You can see the portlet as shown below:

Move your mouse over this icon to see the image

Mapping a Portlet Parameter to a Page Parameter

Back to Topic List

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.

Move your mouse over this icon to see the image

2. Click the Parameters tab.

Move your mouse over this icon to see the image

3. In the Portlet Parameter Values section, click the HR : MyJDeveloper Portlet link.

Move your mouse over this icon to see the image

4. In the Portlet Parameter section, select Page Parameter from the list.

Move your mouse over this icon to see the image

5. Select dept from the second list.

Move your mouse over this icon to see the image

6. Click OK.

Move your mouse over this icon to see the image

7.

Click the View Page link at the top to preview the page.

Move your mouse over this icon to see the image

Notice that the value for the My Department parameter is now displayed. The Java portlet refreshes when different pie slices are clicked.

Move your mouse over this icon to see the image

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 Oracle Portal Center Home.

If you have questions or comments, please post them in the Oracle by Example discussion forum on the Oracle Technology Network.

 Place the cursor on this icon to hide all screenshots.

Copyright © 2004, Oracle Corporation. All rights reserved. Contact Us • Legal Notices and Terms of Use • Privacy Statement