





















































Over 80 great recipes to develop and deploy fast, secure, and modern web applications with Oracle Application Express 4.0
In APEX 4.0, Oracle introduced the plug-in. A plug-in is an extension to the existing functionality of APEX. The idea behind plug-ins is to make life easier for developers. Plug-ins are reusable and can be exported and imported. In this way, it is possible to create functionality which is available to all APEX developers. It is also possible to install and use them without having knowledge of what is inside the plug-in.
APEX is actually a program that converts your settings from the APEX builder to HTML and JavaScript. For example, if you created a text item in the APEX builder, APEX converts this to the following code (simplified):
<input type="text" id="P12_NAME" name="P12_NAME" value="your name">
When you create an item type plug-in, you actually take over this conversion task of APEX and you generate the HTML and JavaScript code yourself by using PL/SQL procedures. That offers a lot of flexibility because now you can make this code generic so that it can be used for more items.
The same goes for region type plug-ins. A region is a container for forms, reports, and such. The region can be a div or a HTML table. By creating a region type plug-in, you create a region yourself with the possibility to add more functionality to the region.
There are four types of plug-in:
In this article, we will discuss all four types of plug-in.
In an item type plug-in you create an item with the possibility of extending its functionality. To demonstrate this, we will make a text field with a tooltip. This functionality is already available in APEX 4.0 by adding the following code to the HTML form element attributes text field in the Element section of the text field:
onmouseover="toolTip_enable(event,this,'A tooltip')"
But you have to do this for every item that should contain a tooltip. This can be made more easy by creating an item type plug-in with a built-in tooltip. And if you create an item of type plug-in, you will be asked to enter some text for the tooltip.
For this recipe, you can use an existing page with a region where you can put some text items on.
function render_simple_tooltip (
p_item in apex_plugin.t_page_item
, p_plugin in apex_plugin.t_plugin
, p_value in varchar2
, p_is_readonly in boolean
, p_is_printer_friendly in boolean )
return apex_plugin.t_page_item_render_result
is
l_result apex_plugin.t_page_item_render_result;
begin
if apex_application.g_debug
then
apex_plugin_util.debug_page_item (
p_plugin => p_plugin
, p_page_item => p_item
, p_value => p_value
, p_is_readonly => p_is_readonly
, p_is_printer_friendly => p_is_printer_friendly);
end if;
--
sys.htp.p('<input type="text" id="'||p_item.name||'" name="'||p_item.name||'" class="text_field" onmouseover="toolTip_enable(event,this,'||''''||p_item.attribute_01||''''||')">');
--
return l_result;
end render_simple_tooltip;
This function uses the sys.htp.p function to put a text item on the screen. On the text item, the onmouseover event calls the function tooltip_enable(). This function is an APEX function and can be used to put a tooltip on an item. The arguments of the function are mandatory.
The function starts with the option to show debug information. This can be very useful when you have created a plug-in and it doesn't work. After the debug information the htp.p function puts the text item on the screen, including the call to tooltip_enable. You can also see that the call to tooltip_enable uses p_item.attribute_01. This is a parameter that you can use to pass a value to the plug-in. That is the following step in this recipe.