Oracle9iAS Portal Developer Kit (PDK)
How to Build a PL/SQL Portlet

Last Update: November 1, 2000
Status: Production
Version: Any PDK Release

Introduction

Once you have successfully installed and deployed the PL/SQL sample portlets supplied by the PDK, you may want to build your own PL/SQL portlets. You can do this by simply modifying the code of the given samples. This will enable you to implement any additional functionality to the default behavior of the portlets. This will also accelerate the process of building portlets from scratch since you only write minimal code.

This article describes how to build a basic PL/SQL portlet using a given sample. This provides a guideline for building upon given samples to add any new features. This article will specifically deal with modifying the way in which a portlet is displayed on a page. After reading this article, please review the An Overview of Writing Portlets for Database Providers article for information on adding additional modes to your portlet.

Assumptions

You have already installed the samples downloaded with the PDK and understand the steps required to display a PL/SQL portlet on a portal page.

Creating a New Portlet

This section describes how to build your own PL/SQL portlet using the HelloWorld sample in PDK.

The HelloWorld sample is a portlet that is contained in the Starter Provider sample. The Starter Provider sample consists of the following files:

  1. starter_provider.pks: The package specification of the starter provider.
  2. starter_provider.pkb: The package body of the starter provider.
  3. helloworld_portlet..pks: The package specification of the hello world portlet.
  4. helloworld_portlet.pkb: The package body of the hello world portlet.
  5. snoop_portlet.pks: The package specification of the snoop portlet.
  6. snoop_portlet.pks: The package body of the snoop portlet.
  7. insintpr.sql: The installation script for the starter provider.

STEP 1 - Implement Portlet Package

The instructions below guide you through the steps of how to modify the helloworld_portlet.pks and helloworld_portlet.pkb files to create your own portlet package. The lines of code in blue describe what you need to change.

From the downloaded samples, take the helloworld_portlet.pks and helloworld_portlet.pkb files which are the package specification and package body for this portlet.

    create or replace package body my_first_portlet is

    ...

    function get_portlet_info(
    p_provider_id in integer,
    p_language in varchar2
    ) return wwpro_api_provider.portlet_record is
    l_portlet wwpro_api_provider.portlet_record;
    begin
    l_portlet.id := starter_provider.PORTLET_FIRST;
    l_portlet.provider_id := p_provider_id;
    l_portlet.title := 'My First Portlet';
    l_portlet.name := 'My_First_Portlet';
    ...
    end get_portlet_info;

    ...

    procedure show(
    p_portlet_record in out wwpro_api_provider.portlet_runtime_record
    ) is
    l_portlet wwpro_api_provider.portlet_record;
    l_text_name varchar2(200);
    l_text varchar2(200);
    begin
    ...

    /*
    Display the content of the portlet in the show mode.
    */
    htp.p(wwui_api_portlet.portlet_text(
    p_string => 'Hello World - Mode Show',
    p_level => 1)
    );

    /*
    Add the functionality you want. In this case we are adding
    a welcome message addressed to the current user.
    */
    l_text_name := 'Welcome to my first portlet ' || wwctx_api.get_user;

    l_text := wwui_api_portlet.portlet_text(
    p_string => l_text_name
    p_level => 1
    );

    htp.p(l_text);
    htp.para;

    if (p_portlet_record.has_border) then
    wwui_api_portlet.close_portlet;
    end if;

    ...

    end show;

    ...

    end my_first_portlet;
    /

STEP 2 - Implement Provider Package

The instructions in this section guide you through the steps that you need to follow to implement the provider package for your portlet. Two options are presented. The first option is to add the portlet to an existing provider package and the second option is to add the portlet in a new package. As a first time portlet developer you may find it easier to add the portlet to an existing provider package.

Option 1 : Add new Portlet to an existing Provider

      create or replace package starter_provider is

      /**
      * This package is used as an example to show how providers can be created
      * in the portal system.
      *
      * This provider contains the following portlets:
      *
      * Hello World (PORTLET_HELLOWORLD)
      * Snoop (PORTLET_SNOOP)
      * My First Portlet (PORTLET_FIRST)
      */

      PORTLET_HELLOWORLD constant integer := 1;
      PORTLET_SNOOP constant integer := 2;
      PORTLET_FIRST constant integer := 3;

      ...

      create or replace package body starter_provider is

      /**
      * Public APIs for the Starter_Provider provider.
      *
      * These methods are required by the provider framework in order
      * to support this provider implementation.
      */
      ...

      function get_portlet(

      p_provider_id in integer,
      p_portlet_id in integer,
      p_language in varchar2

      ) return wwpro_api_provider.portlet_record is
      begin

      if (p_portlet_id = PORTLET_HELLOWORLD) then

      return helloworld_portlet.get_portlet_info(

      p_provider_id = > p_provider_id,
      p_language = > p_language

      );

      elsif

      ... 

      elsif (p_portlet_id = PORTLET_FIRST) then
      return my_first_portlet.get_portlet_info(
      p_provider_id => p_provider_id,
      p_language = > p_language
      );

      ...

      end get_portlet;
      ...

      function get_portlet_list(

      ...

      ) return wwpro_api_provider.portlet_list is

      ...

      begin

      if (p_security_level = false ) then

      ...

      l_cnt := l_cnt + 1;

      l_portlet_list(l_cnt) := get_portlet(

      p_provider_id => p_provider_id,
      p_portlet_id => PORTLET_FIRST,
      p_language => p_language

      );

      ...

      else

      ...

      if (my_first_portlet.is_runnable(

      p_provider_id => p_provider_id,
      p_reference_path => null)

      ) then

      l_cnt := l_cnt + 1;

      l_portlet_list(l_cnt) := get_portlet(

      p_provider_id => p_provider_id,
      p_portlet_id => PORTLET_FIRST,
      p_language => p_language

      );

      end if;

      ...

      end if;

      return l_portlet_list;

      end get_portlet_list;

Option 2 : Add new Portlet to a new Provider

STEP 3 - Add the New Portlet in a Portal Page

Utilities

Alternatively, you can also make use of the PL/SQL Generator for creating a PL/SQL Portlet. The PL/SQL Generator is a utility which generates PL/SQL provider and portlet code. It accepts an XML file (similar in format to the provider.xml file) as input, and generates corresponding provider & portlet skeleton code, which you can then modify according to your requirements.

You can access the hosted version of the PL/SQL Generator here. For more information on the PL/SQL Generator, please refer to this document.

Given below is the sample format of the XML file accepted by the PL/SQL Generator as input.

Please NOTE: The tags shown below in BOLD are mandatory tags which are expected by the PL/SQL Generator. The value of these mandatory tags can be either true or false.

<!-- This is a sample provider.xml for PLSQL Generator -->
<provider>
<portlet>
<name>Test_Portlet</name>
<title>Test Portlet Title</title>
<description>This is a Test portlet</description>
<timeout>30</timeout>
<timeoutMsg>Test Portlet Timed Out</timeoutMsg>
<showEdit>true</showEdit>
<showEditDefault>true</showEditDefault>
<showDetails>true</showDetails>
<showPreview>true</showPreview>
<hasHelp>true</hasHelp>
<hasAbout>true</hasAbout>
<defaultLocale>en.us</defaultLocale>
<imageUrl>http://us.a1.yimg.com/us.yimg.com/i/ww/m5v5.gif</imageUrl>
<thumbnailUrl>http://www.yahoo.com/</thumbnailUrl>
</portlet>
</provider>

Conclusion

  • For the solution to this exercise refer to the howtostarter source files under the plsql category of PDK.
  • Now that you have successfully built a PL/SQL portlet, review the Database Services example source code to add additional features to your portlet such as session storage and customization.
  • Revision History:
    Revision No Last Update
    1.0 July 29, 2002

    Oracle Corporation
    World Headquarters
    500 Oracle Parkway
    Redwood Shores, CA 94065, USA
    http://www.oracle.com/
    Worldwide Inquiries:
    1-800-ORACLE1
    Fax 650.506.7200
    Copyright and Corporate Info