Generating the cooltip for ADF applications (using JHeadstart)

0

Our end users – inspired by the Interaction Designers – have requested a superduper tooltip for their fields. Not the shy title popup label that browsers show for elements with the title attribute set (limited in number of characters and layout options), no, a real sturdy tooltip. It has to look something like this:

Implementing this tooltip on all fields that we want to specify one for is somewhat of a challenge. Not because it is complicated: it is very simple to add such a hovering tooltip to an input component. All it takes is ....
setting the onmouseout and onmouseover attributes:

  &lt;af:inputText id=&quot;EmpInDeptEname&quot;<br />                value=&quot;#{bindings.EmpInDeptEname.inputValue}&quot;<br />                label=&quot;#{nls['EMPINDEPT_ENAME']}&quot;<br />                onmouseover=&quot;showToolTip(this,'#{nls['EMPINDEPT_ENAME']}','#{nls['EMPINDEPT_ENAME_HINT']});&quot;<br />                onmouseout=&quot;hideToolTip();&quot;&gt;&lt;/af:inputText&gt;<br />       &nbsp;<br />

The real challenge is adding these attributes to all elements that we need a tooltip for. That is lot of work, not a lot of fun. However, we generate our application using JHeadstart. So we should be able to leverage the generator.

And that happens to be very easy. All we need to do is change a few lines in a single template. The file templates/default/common/common_items.vm contains the macro ITEM_HINT. It will set either the shortDesc or the hint attribute of Form Input Elements. However, with just a tiny change, we can make it write the onmouseover and onmouseout attributes that we desire:

#macro (ITEM_HINT)<br />## 1.7AMIS1.0 commented out  #if (${JHS.current.item.hintText}!='')#if ($JHS.service.showHintTextAsPopup)#JHS_PROP(&quot;shortDesc&quot; ${JHS.nls(${JHS.current.item.hintText}, &quot;${JHS.current.group.name}_${JHS.current.item.name}_HINT&quot;)})#else#JHS_PROP(&quot;tip&quot; ${JHS.nls(${JHS.current.item.hintText}, &quot;${JHS.current.group.name}_${JHS.current.item.name}_HINT&quot;)})#end#end#end<br />## 1.7AMIS1.0 modified, to support AMIS style tooltip<br />#if (${JHS.current.item.hintText}!='') onmouseover=&quot;showToolTip(this,'${JHS.nls(${JHS.current.item.promptInForm}, &quot;${JHS.current.group.name}_${JHS.current.item.name}&quot;)}','${JHS.nls(${JHS.current.item.hintText}, &quot;${JHS.current.group.name}_${JHS.current.item.name}_HINT&quot;)}');&quot; <br />onmouseout=&quot;hideToolTip();&quot;#end#end <br />

Note: you should (and we did that, honestly) create your own template as a copy of common_items.vm, rather than change the original template file as shipped with JHeadstart. We created /templates/amis/common/amis_common_items.vm and registered our own file in templates/config/jag-config.xml.

To also generate the tooltip into the column header, to achieve this result:

we need to add a call to the ITEM_HINT() macro in the COLUMN_HEADER_LABEL():

#macro (COLUMN_HEADER_LABEL)<br />value=&quot;${JHS.nls(${JHS.current.item.promptInTable}, &quot;${JHS.current.group.name}_TABLE_${JHS.current.item.name}&quot;)}&quot;<br />## 1.7AMIS1.0 Added the call to ITEM_HINT()<br />#ITEM_HINT()<br />#end<br />&nbsp;

There is one tiny little issue: the tooltip should also be shown when the item is read only. However, it is not: the onmouseover and onmouseout attributes are not rendered for the items in read only mode. I am not sure yet how to deal with that particular problem. wrapping every item in a PanelGroup and setting the mouse attribute on the PanelGroup? Use disabled rather than read-only? Make use of the fact that every read only element is rendered using a SPAN that has the element’s ID as its ID?

Share.

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PLSQL), Service Oriented Architecture, BPM, ADF, Java in various shapes and forms and many other things. Author of the Oracle Press book: Oracle SOA Suite 11g Handbook. Frequent presenter on conferences such as JavaOne, Oracle OpenWorld, ODTUG Kaleidoscope, Devoxx and OBUG. Presenter for Oracle University Celebrity specials.

Comments are closed.