Skip Headers
Oracle® WebCenter Framework Building a WebCenter Application Step by Step
10g (10.1.3.2.0)

Part Number B31073-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

2 Building Your Portlets

In this chapter, you will learn how to build two different types of portlets: a Java portlet that uses JSR 168 and a PDK-Java portlet that uses Oracle-specific APIs.

This chapter contains the following sections:

Before You Begin

Before you begin the steps in this chapter, ensure that you have completed the steps in the install.html file located in the sample files you downloaded. Then, perform the following steps:

Creating a Project for Your Portlets

To make it easy to find things in your application, you can create projects to contain your portlets.

To create a project for your portlets:

  1. In the Applications Navigator, right-click the SRDemoSample _Starter application and select New Project.

  2. In the Items list, shown in Figure 2-1, select Empty Project and click OK.

    Figure 2-1 Create an Empty Project

    Description of Figure 2-1 follows
    Description of "Figure 2-1 Create an Empty Project"

  3. In the Project Name field, enter ProdDetailPortlet.

  4. Use the default directory name, then click OK to create the project.

  5. To view the project properties, right-click the project name (in this case, ProdDetailPortlet), then choose Project Properties from the pop-up menu.

  6. Select the technology scope of the project (that is, the technologies you will be including in the project): Java, JSP and Servlets, and Portlet, as shown in Figure 2-2.

    Figure 2-2 Technology Scope of Your New Project

    Description of Figure 2-2 follows
    Description of "Figure 2-2 Technology Scope of Your New Project"

  7. Click OK.

  8. Create a second project by following steps 1 through 7 again, and name the project SRStatusPortlet.

  9. Save the application.

Creating an Application Server Connection to the Oracle WebCenter Preconfigured OC4J

Before you can deploy portlets to your application serverOracle JDeveloper, you first need to establish a connection to your Oracle WebCenter Preconfigured OC4J, which is embedded in Oracle JDeveloper.

To create an application server connection to the preconfigured OC4J:

  1. In Oracle JDeveloper, click the Start WebCenter Preconfigured OC4J icon. A readme.html file displays that contains the connection information for the preconfigured OC4J.

  2. In the Connections Navigator, right-click Connections and select New Application Server Connection.

    Tip:

    If you cannot see the Connections Navigator, select Connection Navigator from the View menu.
  3. If you are on the Welcome page of the Create Application Server Connect Wizard, click Next to display the Type page.

  4. In the Connection Name field, shown in Figure 2-3, enter SRDemoConnection.

  5. From the Connection Type list, select Standalone OC4J 10g 10.1.3.

    Figure 2-3 Create Application Server Connection: Type

    Description of Figure 2-3 follows
    Description of "Figure 2-3 Create Application Server Connection: Type"

  6. Click Next to display the Authentication page.

  7. Enter the Application Server Control Console administrator's user name and password for the relevant middle tier. Typically, the administrator's user name is oc4jadmin and the password is welcome.

  8. Click Next to display the Connection page.

  9. In the Host Name field, enter localhost.

  10. In the RMI Port field, enter the port number to which the Remote Method Invokation (RMI) server binds to the OC4J server. The default value for the preconfigured OC4J is 22667.

  11. Click Next to display the Test page.

  12. Click Test Connection to verify the connection. A success message should appear if everything is correct. If the test fails, you may need to review your connection information.

  13. Click Finish.

Step 1: Building the Product Details Portlet (a JSR 168 Portlet)

To build a simple JSR 168 portlet, we've included steps for building a sample Service Requests Status portlet. Once you deploy this portlet, you will be able to add it to your My Acme page. To view a live demo version of a more highly interactive JSR 168 portlet using Ajax, simply run the completed version of the Service Request Demo.

For more information about JSR 168 portlets, refer to Oracle WebCenter Framework Developer's Guide.

Building a JSR 168 portlet involves the following tasks:

Creating a JSR 168 Portlet

Oracle WebCenter Framework provides a Java Portlet Wizard that enables you to quickly create a simple implementation for each mode of your portlet. Let us use this wizard to get started creating our portlet.

To create a JSR 168 portlet:

  1. In Oracle JDeveloper, the Applications Navigator, within the SRDemoSample_Starter application, right-click the ProdDetailsPortlet project and select New.

    Tip:

    If this project does not exist, follow the instructions provided in Creating a Project for Your Portlets earlier in this chapter.
  2. In the New Gallery, expand the Web Tier category and select Portlets.

  3. In the Items list, shown in Figure 2-4, select Standards-based Java Portlet (JSR 168) to build a JSR 168 portlet.

    Figure 2-4 Create a New JSR 168 Portlet

    Description of Figure 2-4 follows
    Description of "Figure 2-4 Create a New JSR 168 Portlet"

  4. Click OK to display the JSR 168 Java Portlet Wizard.

  5. If you are on the Welcome page of the wizard, click Next to display the Web Application page.

  6. Select Servlet 2.4\JSP 2.0 (J2EE 1.4).

    Tip:

    If a Web application has already been created for the project, you may not see this page of the wizard and instead go straight to the General Portlet Properties page.
  7. Click Next to display the General Portlet Properties page.

  8. In the Name and Class fields, shown in Figure 2-5, enter ProductDetailsPortlet and clear the Enable WSRP V2-inter-portlet communication using Oracle extensions check box.

    The wizard creates a class with this name to represent the portlet.

    Figure 2-5 JSR 168 Portlet General Portlet Properties

    Description of Figure 2-5 follows
    Description of "Figure 2-5 JSR 168 Portlet General Portlet Properties"

  9. Click Next.

  10. In the Display Name field, shown in Figure 2-6, enter Product Details Portlet.

  11. In the Portlet Title field, enter Product Details Portlet.

  12. In the Short Title field, enter Product Details.

  13. Figure 2-6 JSR 168 Portlet Name and Attributes

    Description of Figure 2-6 follows
    Description of "Figure 2-6 JSR 168 Portlet Name and Attributes"

  14. Click Finish to accept the default settings for the rest of the portlet attributes.

    Your Product Details portlet now displays in the Applications Navigator as shown in Figure 2-7.

    Figure 2-7 Product Details Portlet in the Applications Navigator

    Description of Figure 2-7 follows
    Description of "Figure 2-7 Product Details Portlet in the Applications Navigator"

  15. Save your work.

Creating a Web Service Proxy for Your JSR 168 Portlet

This JSR 168 portlet uses a Web Service as its data source. Before you can use a Web Service with a portlet in your application, you must first create a Web Service proxy for your portlet project.

To create a Web Service proxy:

  1. Right-click the ProdDetailPortlet project that contains your ProductDetailsPortlet, then choose New.

  2. Under the Business Tier node, shown in Figure 2-8, choose Web Services, then choose Web Service Proxy.

    Tip:

    If you do not see the Business Tier node in the New Gallery, you may need to Filter By All Technologies by selecting the option from the drop-down list.

    Figure 2-8 New Gallery: Web Service Proxy

    Description of Figure 2-8 follows
    Description of "Figure 2-8 New Gallery: Web Service Proxy"

  3. Click OK.

  4. On the Welcome page of the wizard, click Next.

  5. On the Web Service Description page, shown in Figure 2-9, enter the WSDL of the Web Service , such as:

    http://localhost:8888/ProductDetailsWS/ProductDetailsWSSoapHttpPort?WSDL
    

    Note:

    In this WSDL, localhost and port refer to the system where you deployed the Web Service. The Web Service is deployed in the SRDemo OC4J.

    Figure 2-9 Set the Web Service Description

    Description of Figure 2-9 follows
    Description of "Figure 2-9 Set the Web Service Description"

  6. Click Next.

    Note:

    You may need to click Next again if you do not see the Building Model dialog box display.
  7. After Oracle JDeveloper builds the model for the Web Service, you should see the page shown in Figure 2-10, where you can validate the end point URL for your Web Service:

    Figure 2-10 Validate the Web Service Port Endpoints

    Description of Figure 2-10 follows
    Description of "Figure 2-10 Validate the Web Service Port Endpoints"

  8. Click Finish to accept the default values for the rest of the Web Service Proxy parameters.

  9. Close the ProductDetailsWSSSoapHttpPortClient.java file.

Adding Portlet Logic to a JSR 168 Portlet

At the moment your portlet does not do very much. In fact, it just displays a Welcome message and allows the end user to personalize the portlet title. To make the portlet perform the specific function that you require, you need to extend the sample code with the business logic that implements the desired functionality and features.

First, your portlet will display a list of product types. The list is retrieved from a Web service. Later on, you will extend the portlet, allowing the end user to pick a product type, and select a particular product. When selecting a product, detailed information will display, including a brief description, and an image.

To add portlet logic to a JSR 168 portlet:

  1. In the Applications Navigator, expand the Web Content node, right-click view.jsp, then select Open to open the file in the Visual Editor.

    Tip:

    To locate view.jsp, expand the following nodes under the SRDemoSample_Starter application: Portlets > Web Content > ProductDetailsPortlet\html.
  2. At the bottom of the Visual Editor, click the Source tab to view the source code of the page.

  3. Replace the existing code with the code shown in Example 2-1.

    Example 2-1 Code for view.jsp

    <%@ page contentType="text/html"
    import="javax.portlet.*,java.util.*,portlets.ProductDetailsPortlet,portlets.resource.ProductDetailsPortletBundle"%>
     
    <%@ page contentType="text/html"
    import="portlets.proxy.ProductDetailsWSSoapHttpPortClient,portlets.proxy.types.productdetailsws.types.ProductDetailsBean"%>
     
    <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
     
    <portlet:defineObjects/>
     
    <%
        String prodType = renderRequest.getParameter("prodType");
    %>
     
    <table cellpadding="10%">
     <tr>
      <td>
       <font class="portlet-section-header">
          Product Types
       </font>
      </td>
      <td>
       <font class="portlet-section-header">
          Products
       </font>
      </td>
      <td>
       <font class="portlet-section-header">
          Details
       </font>
      </td>
     </tr>
     <tr>
       <td>
    <%
       ProductDetailsWSSoapHttpPortClient proxy = new ProductDetailsWSSoapHttpPortClient();
       Vector productTypes =  proxy.getProductTypes();
           for (int i=0; i<productTypes.size(); i++)
           {
              PortletURL productURL = renderResponse.createRenderURL();
              productURL.setParameter ("prodType", productTypes.elementAt(i).toString());   
    %>
            
             <font class="portlet-font">
        
               <a href="<%=productURL%>">
                 <%= productTypes.elementAt(i) %>
               </a></font><br>
    <%
           }
    %>
     
      </td>
     </tr>
    </table>
    
  4. From the File menu, select Save All.

Deploying a JSR 168 Portlet to an Application Server

After you have finished building your portlet, you need package it and deploy to the portlet container.

  1. In the Applications Navigator, right-click the ProdDetailPortlet project and select New.

  2. In the New Gallery, expand the General category and select Deployment Profiles.

  3. In the Items list, shown in Figure 2-11, select WAR File.

    Figure 2-11 Create a WAR Deployment File

    Description of Figure 2-11 follows
    Description of "Figure 2-11 Create a WAR Deployment File"

  4. Click OK to display the Create Deployment Profile -- WAR File dialog box.

    Tip:

    You can also get to this dialog box by right-clicking the web.xml file in the Applications Navigator and selecting Create WAR Deployment File.
  5. In the Deployment Profile Name field, shown in Figure 2-12, enter ProductDetailsPortlet.

  6. Use the default directory.

    Figure 2-12 Create Deployment Profile -- WAR File Dialog Box

    Description of Figure 2-12 follows
    Description of "Figure 2-12 Create Deployment Profile -- WAR File Dialog Box"

  7. Click OK to display the WAR Deployment Profile Properties dialog box.

  8. Select Specify J2EE Web Context Root, and in the corresponding field, enter ProductDetailsPortlet as shown in Figure 2-13.

    Figure 2-13 WAR Deployment Profile Properties

    Description of Figure 2-13 follows
    Description of "Figure 2-13 WAR Deployment Profile Properties"

  9. Click OK.

  10. In the Applications Navigator, shown in Figure 2-14, expand the Portlets > Resources node to see the deployment file.

    Figure 2-14 ProductDetailsPortlet.deploy in the Applications Navigator

    Description of Figure 2-14 follows
    Description of "Figure 2-14 ProductDetailsPortlet.deploy in the Applications Navigator"

  11. From the File menu, choose Save All.

  12. Right-click ProductDetailsPortlet.deploy and, from the Deploy to menu, shown in Figure 2-15, choose SRDemoConnection.

    The Configure Application dialog box displays.

    Figure 2-15 Configure Application Dialog Box

    Description of Figure 2-15 follows
    Description of "Figure 2-15 Configure Application Dialog Box"

    Note:

    If SRDemoConnection does not appear in the menu, follow the steps provided in the step Creating an Application Server Connection to the Oracle WebCenter Preconfigured OC4J earlier in this chapter.
  13. Click OK.

  14. When the Deployment finished message displays in the Deployment Log, verify that no errors occurred.

Register the Producer

Now that you have created and deployed your portlet, you are ready to consume it in your application. You register the portlet producer with the application which enables you (or the application developer) to add the portlet to a page.

To register the producer:

  1. Since portlet producers are associated with your application, you can right-click the application or any project within the application to invoke. The easiest way, however, is to open the New Gallery from the UserInterface project. The technology scope of the UserInterface project is set up so that the producer registration wizards show up in your New Gallery.

  2. Choose New from the pop-up menu.

  3. Under Web Tier > Portlets, choose WSRP Producer Registration, then click OK.

    Tip:

    If you do not see the Business Tier node in the New Gallery, you may need to Filter By All Technologies by selecting the option from the drop-down list.
  4. On the Welcome page, click Next.

  5. On the Name page, shown in Figure 2-16, enter ProductDetailsProducer in the Name field, then click Next.

    Figure 2-16 WSRP Producer Name

    Description of Figure 2-16 follows
    Description of "Figure 2-16 WSRP Producer Name"

  6. On the Connection page, shown in Figure 2-17, enter the URL for the WSRP container of your preconfigured OC4J, for example:

    http://localhost:6688/ProductDetailsPortlet/portlets/wsrp1?WSDL
    

    Figure 2-17 WSRP Producer URL

    Description of Figure 2-17 follows
    Description of "Figure 2-17 WSRP Producer URL"

  7. Click Next.

  8. After Oracle JDeveloper creates the connection, click Finish. When the success message displays, click OK.

    Figure 2-18 Successful WSRP Producer Registration Message

    Description of Figure 2-18 follows
    Description of "Figure 2-18 Successful WSRP Producer Registration Message"

  9. The portlet is now ready for you to add to a page.

Step 2: Building the Service Request Status Portlet (a PDK-Java Portlet)

In our Service Request application, we want to be able to display the current status of a particular service request, given the service request ID. We can build a portlet to display this information.

For more information about PDK-Java portlets, refer to the Oracle WebCenter Framework Developer's Guide.

Building a PDK-Java portlet involves the following tasks:

Creating a PDK-Java Portlet and Producer

Oracle WebCenter Framework provides a Java Portlet Wizard that enables you to quickly create a simple implementation for each mode of your portlet. Let's use this wizard to get started creating our portlet.

  1. In Oracle JDeveloper, in the Applications Navigator, expand the SRDemoSample_Starter application.

  2. Right-click the SRStatusPortlet project and select New.

    Tip:

    If this project does not exist, follow the instructions provided in Creating a Project for Your Portlets earlier in this chapter.
  3. In the New Gallery, expand the Web Tier category and select Portlets.

  4. In the Items list, select Oracle PDK-Java Portlet, as shown in Figure 2-19

    Figure 2-19 Create a New PDK-Java Portlet

    Description of Figure 2-19 follows
    Description of "Figure 2-19 Create a New PDK-Java Portlet"

  5. Click OK to display the Java Portlet Wizard.

  6. If you are on the Welcome page of the wizard, click Next to display the Web Application page.

  7. Click Next to display the Portlet Description page.

  8. In the Portlet Name field, enter SRStatusPortlet.

    This is an internal name only and is not exposed to end users.

  9. In the Display Name field, enter Service Request Status Portlet.

    This is the name that appears in portlet selection lists, such as the Oracle JDeveloper Component Palette, where users choose which portlets to add to a page.

  10. In the Description field, enter:

    This portlet displays status information about a given service request.

  11. In the Timeout (seconds) field, leave the default value of 40.

  12. In the Timeout message field, enter:

    Service Request Status Portlet timed out

    Figure 2-20 Portlet Description Page

    Description of Figure 2-20 follows
    Description of "Figure 2-20 Portlet Description Page"

  13. Click Next to display the View Modes page.

  14. The Show page check box is selected by default. For Show mode:

    1. In the Implementation style list, make sure JSP is selected.

    2. In the File name field, keep the default value of SRStatusPortletShowPage.jsp.

  15. We will not have a Show Details mode for this portlet, so leave the Show details page check box cleared.

    Figure 2-21 Show Modes Page

    Description of Figure 2-21 follows
    Description of "Figure 2-21 Show Modes Page"

  16. Click Next to display the Customize Modes page.

  17. The Edit page check box is selected by default. For the Edit mode:

    1. In the Implementation style list, make sure that JSP is selected.

    2. In the File name field, keep the default value of SRStatusPortletEditPage.jsp.

  18. We will not have an Edit Defaults mode for this portlet, so leave the Edit Defaults page check box cleared.

    Figure 2-22 Customize Modes Page

    Description of Figure 2-22 follows
    Description of "Figure 2-22 Customize Modes Page"

  19. Click Next to display the Additional Modes page.

  20. Select the Help page check box. For Help mode:

    1. From the Implementation style list, select HTML File.

    2. In the File name field, keep the default value of SRStatusPortletHelpPage.html.

  21. Select the About page check box. For About mode:

    1. From the Implementation style list, select HTML File.

    2. In the File name field, keep the default value of SRStatusPortletAboutPage.html.

    Figure 2-23 Additional Modes Page

    Description of Figure 2-23 follows
    Description of "Figure 2-23 Additional Modes Page"

  22. Click Next to display the Public Portlet Parameters page.

  23. On the Public Portlet Parameters page, click Add.

  24. Change the Name of the new parameter to ServiceReqID.

  25. Change the Display Name of the new parameter to ServiceReqID.

  26. Change the Description of the new parameter to Service Request ID.

    Figure 2-24 Public Portlet Parameter

    Description of Figure 2-24 follows
    Description of "Figure 2-24 Public Portlet Parameter"

  27. Click Next to display the Public Portlet Events page.

  28. Click Next to display the Producer Description page.

  29. In the Producer name field, enter srstatusproducer.

  30. Ensure all the check boxes are selected: Generate deployment properties file, Generate XML entries, Generate index JSP.

    Figure 2-25 Producer Description Page

    Description of Figure 2-25 follows
    Description of "Figure 2-25 Producer Description Page"

  31. Click Finish to generate the files for your portlet. If you expand all the nodes under the SRStatusPortlet project in the Applications Navigator, you should see the following files:

    • A file for each portlet mode you selected:

      • SRStatusPortletAboutPage.html

      • SRStatusPortletEditPage.jsp

      • SRStatusPortletHelpPage.html

      • SRStatusPortletShowPage.jsp

    • web.xml

    • _default.properties

    • srstatusproducer.properties

    • provider.xml

    • index.jsp

    All of these files are required to deploy and run the portlet successfully, except for index.jsp, which is used by Oracle JDeveloper for testing purposes.

    Figure 2-26 Files Generated for the Service Request Status Portlet

    Description of Figure 2-26 follows
    Description of "Figure 2-26 Files Generated for the Service Request Status Portlet"

  32. From the File menu, select Save All.

Adding Portlet Logic to a PDK-Java Portlet

At the moment, your portlet does not do very much. In fact, it just displays a welcome message and allows the end user to personalize the portlet title. To make the portlet perform the specific function that you require, you need to extend the sample code with wht business logic that implements the desired functionality and features.

The Service Request Portlet needs to query the SRDemo database to find out the status of a particular service request, given its service request ID, and then display that information in a table.

  1. In the Applications Navigator, right-click the SRStatusPortlet project and select New.

  2. In the New Gallery, expand the General category and select Simple Files.

  3. In the Items list, select Java Class.

    Figure 2-27 Create a Java Class

    Description of Figure 2-27 follows
    Description of "Figure 2-27 Create a Java Class"

  4. Click OK to display the Create Java Class dialog box.

  5. In the Name field, enter SRConnectionUtil.

  6. Leave the rest of the options in this dialog box as their default values.

    Figure 2-28 Create Java Class Dialog Box

    Description of Figure 2-28 follows
    Description of "Figure 2-28 Create Java Class Dialog Box"

  7. Click OK.

  8. Replace the generated code with the code shown in Example 2-2.

    Example 2-2 Code to Create a Connection to the SRDemo Database

    package srstatusportlet;
     
    import java.sql.Connection;
    import java.sql.SQLException;
     
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
     
    import javax.sql.DataSource;
     
     
    public class SRConnectionUtil {
        public SRConnectionUtil() {
        }
        
        public static Connection getConnection ()
        { 
          InitialContext ctx;
          DataSource ds;
          Connection conn = null;
          try
          {
            ctx = new InitialContext();
            ds = (DataSource) ctx.lookup("jdbc/SRDemoCoreDS");
            conn = ds.getConnection();
          }
          catch (NamingException ne) 
          {
            conn = null;
          }
          catch (SQLException sqle) 
          {
            conn = null;
          };
          return conn;
        }   
        
    }
    

    This class creates a connection to the SRDemo database, against which we will execute a query in the portlet code.

  9. Save the file.

  10. If you have not already done so, create a database connection pointing to your srdemo schema as described in the install.html file located in the sample files you downloaded.

  11. In the Applications Navigator, right-click SRStatusPortletShowPage.jsp and select Open.

  12. Select the Source tab to view the source code for the page.

  13. Select the existing code and replace it with the code shown in Example 2-3.

    Example 2-3 Code for the Service Request Status Portlet

    <%@page contentType="text/html; charset=windows-1252"
            import="oracle.portal.provider.v2.render.PortletRenderRequest"
            import="oracle.portal.provider.v2.http.HttpCommonConstants"
            import="oracle.portal.provider.v2.ParameterDefinition"
            import="srstatusportlet.SRConnectionUtil"
            import="java.sql.Connection"
            import="java.sql.Statement"
            import="java.sql.ResultSet"
            import="java.sql.SQLException"
    %>
     
    <%
       PortletRenderRequest pReq = (PortletRenderRequest)
          request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
          
       // Reading the service request ID, as a parameter
       String SRID = pReq.getParameter("ServiceReqID");
     
       // Creating the database connection
       Connection conn = SRConnectionUtil.getConnection();
       
       // Testing if the parameter has been wired. If no parameter is passed
       // it is set to 104, by default.
       if (SRID == null)
       {
         %>
         Please map the service request ID to this portlet's input parameter.
         <%
         SRID = "104";
       }
       
       if (conn == null) {
        %>
        Couldn't connect to the database.
        <%
       } 
       else
         try 
         {
          Statement stmt = conn.createStatement();
          // Constructing the SELECT statement
          String query =
              "SELECT svr_id, status, " +
              "users1.first_name || ' ' || users1.last_name createdby, " +
              "users2.first_name || ' ' || users2.last_name assignedto, " + 
              "TO_CHAR(assigned_date, 'Dy, Mon DD, YYYY') " +
              "FROM service_requests, users users1, users users2 " +
              "WHERE svr_id = " + SRID + " AND " +
              "users1.user_id = service_requests.created_by AND " +
              "users2.user_id = service_requests.assigned_to";
                         
          // Executing the query.
          ResultSet rs = stmt.executeQuery(query);
          // Stepping through the result set.
          while (rs.next()) 
          {
    %>
    <table>
     <tr>
      <td>
       <font class="PortletText1">
         Service Request ID:
       </font>
      </td>
      <td>
       <font class="PortletHeading1">
         <%=rs.getInt(1)%>
       </font>
      </td>
     </tr>
     <tr>
      <td>
       <font class="PortletText1">
         Status:
       </font>
      </td>
      <td>
       <font class="PortletHeading1">
         <%=rs.getString(2)%>
       </font>
      </td>
     </tr>
     <tr>
      <td>
       <font class="PortletText1">
         Created on:
       </font>
      </td>
      <td>
       <font class="PortletHeading1">
         <%=rs.getString(5)%>
       </font>
      </td>
     </tr>
     <tr>
      <td>
       <font class="PortletText1">
         Created By:
       </font>
      </td>
      <td>
       <font class="PortletHeading1">
         <%=rs.getString(3)%>
       </font>
      </td>
     </tr>
     <tr>
      <td>
       <font class="PortletText1">
         Assigned To:
       </font>
      </td>
      <td>
       <font class="PortletHeading1">
         <%=rs.getString(4)%>
       </font>
      </td>
     </tr>
    </table>
     
    <%
            } //while
          } // try
          catch (SQLException sqle)
          {
            System.out.println ("DB Connection established successfully but ran into an issue while working with the DB.");
            System.out.println (sqle);
          }
          conn.close();
    %>
    

    This code first calls the Java class we created earlier to connect to the database. Then it sets the service request ID based on a parameter passed to it (if no parameter is passed, the service request ID is set to a default value of 100). Using this service request ID, the portlet then queries the SRDemo database to find the status of the service request. Finally the results of this query are printed in an HTML table.

  14. Save the file.

  15. Right-click SRStatusPortletAboutPage.html and select Open.

  16. In the Design view, enter the following text:

    Service Request Status Portlet

    MyAcme, Copyright

  17. Save the file.

  18. Right-click SRStatusPortletHelpPage.html and select Open.

  19. In the Design view, enter the following text:

    This portlet displays status information about a given service request, based on a parameter (service request ID) it receives. If the portlet does not work as expected, it may not have been wired properly.

  20. Save the file.

Deploying a PDK-Java Portlet to an Application Server

After you have finished building your portlet, you are ready to deploy it to your preconfigured OC4J.

  1. In the Applications Navigator, locate the web.xml file under SRStatusPortlet > Web Content > WEB-INF.

  2. Right-click the web.xml and select Create WAR Deployment Profile

  3. In the Deployment Profile Name field, enter SRStatusPortletApp.

  4. Use the default directory.

    Figure 2-29 Create Deployment Profile -- WAR File Dialog Box

    Description of Figure 2-29 follows
    Description of "Figure 2-29 Create Deployment Profile -- WAR File Dialog Box"

  5. Click OK to display the WAR Deployment Profile Properties dialog box.

  6. Select Specify J2EE Web Context Root, and in the corresponding field, enter SRStatusPortlet.

    Figure 2-30 WAR Deployment Profile Properties Dialog Box

    Description of Figure 2-30 follows
    Description of "Figure 2-30 WAR Deployment Profile Properties Dialog Box"

  7. Click OK.

  8. In the Applications Navigator, expand the Resources node to see the deployment file.

    Figure 2-31 SRStatus Portlet Deployment File

    Description of Figure 2-31 follows
    Description of "Figure 2-31 SRStatus Portlet Deployment File"

  9. From the File menu, choose Save All.

  10. Right-click SRStatusPortletApp.deploy and from the Deploy to menu, select SRDemoConnection.

    The Configure Application dialog box displays.

    Note:

    If SRDemoConnection does not appear in the menu, follow the steps provided in Creating an Application Server Connection to the Oracle WebCenter Preconfigured OC4J earlier in this chapter.
  11. You can accept the defaults here, so click OK.

  12. When the Deployment finished message displays in the Deployment Log, verify that no errors occurred.

    Figure 2-32 Deployment Log

    Description of Figure 2-32 follows
    Description of "Figure 2-32 Deployment Log"

  13. Register the producer following the same steps you used in "Register the Producer" for the JSR 168 portlet, using the URL:

    http://localhost:6688/SRStatusPortlet/providers
    

    The JSR 168 portlet and PDK-Java portlet you created are now ready for you to add to your application.

Summary

In this chapter, you learned how to build a JSR 168 portlet and a PDK-Java portlet and how to deploy them for use with a WebCenter application. You can now register the producer with an application and add the portlet to a page. You will do just that in Chapter 7, "Building a Page and Adding Components". Before you move onto building the page and adding components however, you can continue to Chapter 3, "Setting Up Skins".