Save and close starter_provider2.pkb.

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 Creating PLSQL Portlets 8-17 is begin -- -- Create a path for the portlet instance. This is used to create -- the preferences for the portlet instance in the preference store. -- wwpre_api_name.create_path p_path = PORTLET_PATH || p_portlet_instance.reference_path ; -- -- Create the names to store the portlet preferences. -- wwpre_api_name.create_name p_path = PORTLET_PATH || p_portlet_instance.reference_path, p_name = PREFNAME_STRING, p_description = Single custom row in || Introductory Example portlet., p_type_name = NLSID, p_language = wwctx_api.get_nls_language; wwpre_api_name.create_name p_path = PORTLET_PATH || p_portlet_instance.reference_path, p_name = PREFNAME_TITLE, p_description = Single custom row in || Introductory Example portlet., p_type_name = NLSID, p_language = wwctx_api.get_nls_language; exception when others then raise; end register; 3. The deregister procedure must eliminate the preference store with a call to wwpre_api_name.delete_name. procedure deregister p_portlet_instance in wwpro_api_provider.portlet_instance_record is begin -- -- Delete the path used by the portlet instance. This will delete -- all the names and all the values associated with the path. -- wwpre_api_name.delete_path p_path = PORTLET_PATH || p_portlet_instance.reference_path ; exception when others then raise; end deregister; 4. The portlet must also get and set the values in the preference store using wwpre_ api_value.set_value and wwpre_api_value.get_value. Find the get_ default_preference function. Notice how this function loads the system level default values from the preference store. The default preferences are associated with an instance. The language strings are set in the database.