Creating a process type plug-in

A process type plug-in extends the functionality of a page process. This can be anything but it is typically used for APEX built-ins or Internet functionalities like e-mail sender or Twitter update. The benefit of this is that the process type plug-ins can be reused. We will create a process type plug-in which changes the language by using the APEX_UTIL.SET_SESSION_LANG built-in. There are more ways to change the session language but in this recipe, we will use this built-in in a page process to demonstrate how it works.

Getting ready

Make sure you have an existing webpage with a region.

How to do it...

  1. Go to shared components and click Plug-ins.
  2. Click the Create button.
  3. In the name section, enter set_language in the name text field.
  4. In the internal name text field, enter a unique name, for example com.packtpub.set_language.
  5. In the type list box, select Process.
  6. In the PL/SQL code text area, enter the following code:
    function set_language (
    p_process in apex_plugin.t_process,
    p_plugin in apex_plugin.t_plugin )
    return apex_plugin.t_process_exec_result
    is
    Dynamic Attribute mapping
    l_language varchar2(50) := p_process.attribute_01;
    l_result apex_plugin.t_process_exec_result;
    begin
    Set session language
    apex_util.set_session_lang(l_language);
    Set success message
    l_result.success_message := 'Session language switched to '||l_language;
    return l_result;
    end set_language;
    [set_language.sql]
    

The function starts with two arguments, which are necessary but have a default value. The return type is apex_plugin.t_process_exec_result. The actual switch is done by APEX_UTIL.SET_SESSION_LANG.

  1. In the callbacks section, enter set_language in the execution function name.
  2. Click the Create button.
  3. In the custom attributes section, click the Add Attribute button.
  4. In the name section, enter Language in the label text field.
  5. Click the Create button. The process type plug-in is ready. Now we will create a text item and a button to start the process.
  6. Go to your application and click on the page you want to edit.
  7. In the processes section, click the add icon.
  8. Select plug-ins.
  9. Select the plug-in we just created, set_language.
  10. Enter a name for this plug-in, for example, setlang. Click Next.
  11. In the language text field, enter&PX_LANGUAGE. (replace X by the page ID).
  12. Click the Create process button.
  13. In the items section, click the add icon.
  14. Select the Select list.
  15. Enter PX_LANGUAGE (replace X by the page id) in the item name text field.
  16. In the region select list, select the region you want to put this item on. Click Next two times.
  17. In the create item section, set the Page action when value changed list box to Submit Page. Click Next.
    How to do it...
  18. Click the Create or edit static List of Values link.
    How to do it...
  19. In the pop-up window, enter the following languages in both columns:
    How to do it...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.128