Using a rich editor in ADF applications

5

About a year ago Frank Nimphius wrote this weblog article about using a rich text editor called openWYSIWYG in ADF applications. Recently we encountered the need for such an editor in one of our ADF applications. I found Franks article quite useful. However, I also found that I needed to make a few minor modifications to make it really work. Besides that, we have some requirements regarding the availability of some of the toolbar buttons. This next short article describes what modifications my colleague Lucas Jellema and me made to make the openWYSIWYG editor behave like we wanted to.

....

Adjustments needed to make the editor work

The WYSIWYG editor is made available through a JavaScript library. In this library, several paths are defined. These paths point to the popup frames, css files and icon images locations. By default, the lines defining these locations are

imagesDir = &quot;icons/&quot;;<br />cssDir = &quot;styles/&quot;;<br />popupsDir = &quot;popups/&quot;

Since

  • "installing" the wysiwyg editor simply involves unzipping the downloaded zip file and including the JavaScript library in the JSF page
  • we unzipped this zip file in the web root of our web application (public_html)
  • we use JHeadstart to generate our pages and JHeadstart puts them in pubic_html/pages

we needed to modify the paths. Here’s what we set them to

 

imagesDir = &quot;../icons/&quot;;<br />cssDir = &quot;../styles/&quot;;<br />popupsDir = &quot;../popups/&quot;

Making toolbar items invisible

Our business case specifically required us to makje most of the toolbar buttons invisible. We only wanted to enable the end users to be able to make the font bold, italic or underlined and to included bulleted lists. The easiest way to do this is to set the style class of these buttons to "display: none". Besides that, the openWYSIWYG toolbar conatins several separators. We wanted them to be invisible as well.

The solution we came up with was to include an CLASS attribute for each button and separator that is rendered in the toolbar. Then modifying the display attribute of those classes in our css file should render the buttons and separators (in)visible. Inspection of the JavaScript code shows that the buttons all have an ID, e.g.

var ToolbarList = {<br />//Name              buttonID                 buttonTitle           buttonImage                            buttonImageRollover<br />  &quot;bold&quot;:           ['Bold',                 'Bold',               imagesDir + 'bold.gif',               imagesDir + 'bold_on.gif'],<br />  &quot;italic&quot;:         ['Italic',               'Italic',             imagesDir + 'italics.gif',            imagesDir + 'italics_on.gif'],<br />  &quot;underline&quot;:      ['Underline',            'Underline',          imagesDir + 'underline.gif',          imagesDir + 'underline_on.gif']

So, the "bold" button has the ID "Bold", the "italic" button has the ID "Italic" etc. Further inspection of the code shows that both the drop downs for the fonts and the separators do not have such an ID. This means that we made this modification in the same ToolbarList variable shown above:

&nbsp;&nbsp;&nbsp; &quot;separator&quot;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ['Seperator',&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'seperator',&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagesDir + 'separator.gif',&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagesDir + 'separator.gif'],

In other words, the "separator" item now has the ID "Separator". Next, we modified lines 254 and further as well as lines 283 and further like this

			if (buttonName[i]== &quot;Separator&quot;) {<br />		    toolbar += '&lt;td class=&quot;'+buttonID+'&quot; style=&quot;width: 12px;&quot; align=&quot;center&quot;&gt;&lt;img src=&quot;' +buttonImage+ '&quot; border=0 <br />		    unselectable=&quot;on&quot; width=&quot;2&quot; height=&quot;18&quot; hspace=&quot;2&quot; unselectable=&quot;on&quot;&gt;&lt;/td&gt;';<br />			}<br />	    else {<br />		    toolbar += '&lt;td class=&quot;'+buttonID+'&quot; style=&quot;width: 22px;&quot;&gt;&lt;img src=&quot;' +buttonImage+ '&quot; border=0 unselectable=&quot;on&quot; <br />		    title=&quot;' +buttonTitle+ '&quot; id=&quot;' +buttonID+ '&quot; class=&quot;button&quot; onClick=&quot;formatText(this.id,\'' + n + '\');&quot; <br />		    onmouseover=&quot;if(className==\'button\'){className=\'buttonOver\'}; this.src=\'' + buttonImageRollover + '\';&quot; <br />		    onmouseout=&quot;if(className==\'buttonOver\'){className=\'button\'}; this.src=\'' + buttonImage + '\';&quot; unselectable=&quot;on&quot; <br />		    width=&quot;20&quot; height=&quot;20&quot;&gt;&lt;/td&gt;';<br />

This makes sure that each button gets a class attribute that equals the ID of the defined button. Please note that lines 283 and further are different than the ones shown here, but they too got the addition

class=&quot;'+buttonId+'&quot;

In order to render the drop downs invisible we modified lines 242 and 243 like this

&nbsp;&nbsp;&nbsp; toolbar += '&lt;td class=&quot;FontSelect&quot; style=&quot;width: 90px;&quot;&gt;&lt;span id=&quot;FontSelect' + n + '&quot;&gt;&lt;/span&gt;&lt;/td&gt;';<br />&nbsp;&nbsp;&nbsp; toolbar += '&lt;td class=&quot;FontSizes&quot; style=&quot;width: 60px;&quot;&gt;&lt;span id=&quot;FontSizes'&nbsp; + n + '&quot;&gt;&lt;/span&gt;&lt;/td&gt;';<br />

Finally, we modified our css like this:

.FontSelect, .FontSizes, .Seperator, .Subscript, .Superscript, .Justifyleft, <br />.Justifycenter, .Justifyright, .InsertOrderedList, .Outdent, .Indent, .toolbar2<br />{display:none

The final result looks like this:

Share.

About Author

5 Comments

  1. Sebastian Fernandez on

    Hi,
    how can I access to the example of Frank Ninphius?
    I think that the blog is not yet available :-S
    Thanks..

  2. Wouter van Reeven on

    Hi Martin,

    Yes I have used FCKEditor as well in the past. However, as far as I know there is no JSF tag for it. So it may be hard to use it in a JSF application.

    Greets, Wouter