Open starter_provider2.pks in an editor.

Creating PLSQL Portlets 8-13 list function of the provider. The get_portlet_list function tells the portal which portlets the provider implements. function get_portlet_list ... begin l_cnt := 0; if p_security_level = false then l_cnt := l_cnt + 1; l_portlet_listl_cnt := get_portlet p_provider_id = p_provider_id ,p_portlet_id = PORTLET_HELLOWORLD ,p_language = p_language ; l_cnt := l_cnt + 1; l_portlet_listl_cnt := get_portlet p_provider_id = p_provider_id ,p_portlet_id = PORTLET_SNOOP ,p_language = p_language ; l_cnt := l_cnt + 1; l_portlet_listl_cnt := get_portlet p_provider_id = p_provider_id ,p_portlet_id = PORTLET_FIRST ,p_language = p_language ; else if helloworld_portlet.is_runnable p_provider_id = p_provider_id ,p_reference_path = null then l_cnt := l_cnt + 1; l_portlet_listl_cnt := get_portlet p_provider_id = p_provider_id ,p_portlet_id = PORTLET_HELLOWORLD ,p_language = p_language ; end if; if snoop_portlet.is_runnable p_provider_id = p_provider_id ,p_reference_path = null then l_cnt := l_cnt + 1; l_portlet_listl_cnt := get_portlet p_provider_id = p_provider_id ,p_portlet_id = PORTLET_SNOOP ,p_language = p_language ; end if; if my_first_portlet.is_runnable p_provider_id = p_provider_id ,p_reference_path = null then l_cnt := l_cnt + 1; l_portlet_listl_cnt := get_portlet p_provider_id = p_provider_id ,p_portlet_id = PORTLET_FIRST ,p_language = p_language ; end if; end if; 8-14 Oracle Fusion Middleware Developers Guide for Oracle Portal return l_portlet_list; end get_portlet_list; 9. In starter_provider2.pkb, modify the is_portlet_runnable function to add a call to the is_runnable function of the new portlet. function is_portlet_runnable p_portlet_instance in wwpro_api_provider.portlet_instance_record return boolean is begin if p_portlet_instance.portlet_id = PORTLET_HELLOWORLD then return helloworld_portlet.is_runnable p_provider_id = p_portlet_instance.provider_id ,p_reference_path = p_portlet_instance.reference_path ; elsif p_portlet_instance.portlet_id = PORTLET_SNOOP then return snoop_portlet.is_runnable p_provider_id = p_portlet_instance.provider_id ,p_reference_path = p_portlet_instance.reference_path ; elsif p_portlet_instance.portlet_id = PORTLET_FIRST then return my_first_portlet.is_runnable p_provider_id = p_portlet_instance.provider_id ,p_reference_path = p_portlet_instance.reference_path ; else raise wwpro_api_provider.PORTLET_NOT_FOUND_EXCEPTION; end if; end is_portlet_runnable; 10. Repeat step 9 according to the information in Table 8–4 .

11. Save and close starter_provider2.pkb.

Table 8–4 Changes to starter_provider2.pkb ProcedureFunction Addition procedure register_portlet elsif p_portlet_instance.portlet_id = PORTLET_FIRST then my_first_portlet.registerp_portlet_instance procedure deregister_portlet elsif p_portlet_instance.portlet_id = PORTLET_FIRST then my_first_portlet.deregister p_portlet_instance function describe_portlet_ parameters elsif p_portlet_id = PORTLET_FIRST then return my_first_portlet.describe_parameters p_provider_id, p_language; procedure show_portlet elsif p_portlet_record.portlet_id = PORTLET_FIRST then my_first_portlet.showp_portlet_record procedure copy_portlet elsif p_copy_portlet_info.portlet_id = PORTLET_FIRST then my_first_portlet.copyp_portlet_record Creating PLSQL Portlets 8-15 12. Log in to Oracle Portal as you normally would.

13. From the Portal Builder, click the Administer tab then the Portlets tab.

14. From the Portlet Repository portlet, click Display Portlet Repository.

15. Browse the repository and find the starter provider typically it will appear in the Portlet Staging Area of the repository. It should contain its two original portlets: hello world and snoop. 16. From a command line prompt, start SQLPlus and connect as the owner of the starter provider schema. 17. Compile the new and modified PLSQL packages in the following order: ■ starter_provider2.pks ■ my_first_portlet.pks ■ starter_provider2.pkb ■ my_first_portlet.pkb 18. If any compilation errors occur, fix and recompile them until all of the packages compile successfully.

19. From the Portlet Repository portlet, click Display Portlet Repository.

20. Browse the repository and find the starter provider again. It should now contain your new portlet, my_first_portlet, in addition to its original portlets.

8.3.3 Adding Your Portlet to a Page

Your portlet should now be available for adding to pages like any other portlet in the Portlet Repository. To add your portlet to a page, follow the instructions in Oracle Fusion Middleware Users Guide for Oracle Portal.

8.4 Implementing Information Storage

Oracle Portal provides APIs for storing and retrieving individual portlet preferences, and storing and manipulating temporary data for the current session. Implementing information storage consists of the following: ■ Section 8.4.1, Implementing a Preference Store ■ Section 8.4.2, Implementing a Session Store

8.4.1 Implementing a Preference Store

Oracle Portal provides a set of APIs for storing and retrieving individual preferences for each unique portlet instance in a persistent manner. It provides a unique identifier for each individual, a preference store automatically mapped by user, and access mechanisms for storing and retrieving personalization information in your PLSQL portlets. By default, when you enable end-user personalization, Personalize appears on the title bar of your portlet. This link displays a form where users can choose settings for that portlet. Note: If you make changes to an existing provider or the portlet record, you need to refresh your provider before seeing the changes reflected in your Oracle Portal instance. 8-16 Oracle Fusion Middleware Developers Guide for Oracle Portal End-user personalization options are available through the wwpre_api_name and wwpre_api_value packages.

8.4.1.1 Using a Preference Store

In general, you can set up preference storage as follows:

1. Create the preference path using wwpre_api_name.create_path.

2. Create the preference using wwpre_api_name.create_name.

3. Set the preference values by providing the preference name and scoping level for

which you want to set the value. Use wwpre_api_value.set_value_as_ varchar2, set_value_as_number, or set_value_as_date for this purpose.

4. Get preference values by providing the preference name and path whenever you

want to retrieve the preference value. Use wwpre_api_value.get_value_as_ varchar2, get_value_as_number, or get_value_as_date for this purpose.

8.4.1.2 Creating and Accessing a Preference Store

The services example, located in ..\pdkplsql\pdk\plsql\svcex in PDK-PLSQL pdkplsql.zip, illustrates how you can implement preference storage. The objective is to achieve the following functionality: ■ When a user clicks Personalize, they can enter text in two fields. ■ The first field prompts for personalized text. The second prompts for a personalized portlet title. ■ The values the user enters for these two fields are stored in the preference store. ■ The personalized text and portlet titles are retrieved whenever that user invokes the portlet instance. You can browse through this example as follows to see how to create the preference store, store values in it, and retrieve values from it: 1. Open the services_portlet.pkb file in an editor. The portlet path and preference names are provided with aliases in the constants part of your portlet definition. DOMAIN constant varchar230 := provider; SUBDOMAIN constant varchar232 := services; PORTLET_PATH constant varchar2256:= oracle.portal.pdk.servicesportlet.; PREFNAME_STRING constant varchar230 := services_string; PREFNAME_TITLE constant varchar230 := services_title; 2. Find the register procedure. Your portlet needs to create a path for storing preferences. To do so, it calls wwpre_api_name.create_path for creating the preference path. It then calls wwpre_api_name.create_name for creating the preference name, taking the portlet path, name, and description as input parameters. Another input parameter is the p_type_name that indicates special value types. The NLSID type indicates that the value stored is an NLS id. The functions for setting and retrieving this type treat it as a number value. Apart from that, when a preference store value of this type is exported or copied, so are its associated strings. The last input parameter, the language, is obtained from a context API. procedure register p_portlet_instance in wwpro_api_provider.portlet_instance_record