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.
This module covers the following topics:
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.
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.
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.
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 New Gallery 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:
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:
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:
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:
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:
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.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. |
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 portlet's input parameters are...</p> ... And change it to: <P>Hello <b><%= pReq.getUser().getName() %>.</b> The department is: </P> <%
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.
Check whether your changes are reflected. |
| 5. | Click the
Save All icon on the toolbar.
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. |
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:
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.
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. Click Finish. |
| 10. | You should receive a message saying your registration was successful. Click OK. |
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
|
| 4. | In the Portlet Repository, click the Portlet Staging Area link. |
| 5. | Click the < YourName> JDeveloper Provider link. |
| 6. | Click the My JDeveloper Portlet link to move over to the selected portlet area. |
| 7. | Click
OK. The portlet is added to your page.
You can see the portlet as shown below: |
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 View Page 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 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 | |
