Apex spell checker

07Jun10

Problem

The APEX spell checker is rubbish. Many people are stuck with IE6/7 at work, these browsers don’t come with a built in spell checker and the one provided with Apex 3.2 is horrible.

A default APEX install has no dictionary, tables exist to hold one but they are empty. If you are rash enough to populate the dictionary tables you will discover that it’s quite good at spotting spelling mistakes but it only appears to do a soundex to find suggestions and those suggestions come in alphabetical order.  Not good, not good at all.

The APEX version 4 version at apex.oracle.com doesn’t seem to have an option for a spell checker on text areas at all. It is still mentioned in the help though. Are the APEX team going to solve this problem or are they just going to hide the problem child? Firefox and Google Chrome users get the facility from their browser so maybe they think a solution isn’t needed.

Solution

If you have been around the Oracle Forms development world you may have come across a tool called JSpell, a java based spell checker which can be integrated into Forms giving a spell checker for any text field.

Jspell comes in a variety of guises. From the Apex point of view there are two which interest us. The first is JspellHTML which is a spell checker that works like the current APEX one and calls a pop up spell checker at the press of a button. The second is Jspell Evolution (I think that should be said in film trailer voice over style). This is an AJAX check as you type spell checker, and gives one of those wiggly red lines under misspelt words.

Both can be installed into a Oracle Application Server 10.1.2 and used with APEX. Hurrah. They can also be installed into other Java apps servers and IIS but I leave that as an exercise for the reader.

Download the appropriate version from the Jspell website (Jspellhtmlj.zip) and un-zip it

JSpell HTML

Download the appropriate version from the Jspell website (Jspellhtmlj.zip) and un-zip it

I’ll be using the Enterprise Manager interface because its the easiest way of installing an Java app.

In a default OAS 10.1.2 install you will have an OC4J instance called home. Navigate to it.

Navigate to the Applications tab

Deploy the spell war file

Browse for the war file and select it.

Set application name to “jspellhtml”

Set map to URL to “/jspellhtml”

You now have a Jspell deployed to the apps server. You can test it by navigating to http://appservername/jspellhtml/test.html

Now we need to implement it in an Apex page.

First, define the fields that will be checked. We do this by adding some javascript to the HTML header in the page header. This registers the fields that will be checked, they are put into a JS array via the following code. You just need to modify it for your field names.

I have a default form based on the Dept table.

<script language="JavaScript" src="/jspellhtml/jspell.js"></script>

<script language="JavaScript"><!--

function getSpellCheckArray() {
 var fieldsToCheck=new Array();
 // make sure to enclose form/field object reference in quotes!
 fieldsToCheck[fieldsToCheck.length]='document.forms["wwvFlowForm"].P3_DNAME';
 fieldsToCheck[fieldsToCheck.length]='document.forms["wwvFlowForm"].P3_LOC';
 return fieldsToCheck;
}

var language;
//--></script>

Now you just need to create the button to call the spell check. Create a button that redirects to a URL containing this code.

javascript:jspellcheck();

Like this


You should now have a functioning APEX spell checker, assuming you speak Americanish. If you speak a sensible language, Hungarian for instance, then you will need to change the dictionary. Jspell will provide  alternative dictionaries as part of the license.

First off you need a dictionary from the nice people at jspell. Mine is “lex_enGB.jdx” copy that to the apps server \ORACLE_HOME\j2ee\home\applications\jspellhtml\jspellhtml\WEB-INF\jspell. If you are in the right place you will find “lex_enUS.jdx”. This is where your license key goes too.

Navigate to the “home” OC4J in the enterprise manage and restart it.

Now navigate up a couple of levels to \ORACLE_HOME\j2ee\home\applications\jspellhtml\jspellhtml. Here you will find the jspell.js file. Open it and set the “language” variable. E.g.


var language="English (GB)";

You can find the language syntax in the test.html file in the same directory.

JSpell evolution

Jspell Evolution is set up in the same way as JspellHTML. The difference is in the implentation inside APEX.

First the javascript added to the header is different. Note the line initiating JSPELL and the syntax for identifying the fields.

<script TYPE="text/javascript" SRC="/jspellEvolution/jspellSettings.js"  CHARSET="ISO-8859-1"></script>
<script TYPE="text/javascript" SRC="/jspellEvolution/jspellEvolution.js" CHARSET="ISO-8859-1"></script>

<script LANGUAGE="JavaScript" TYPE="text/javascript"> <!--

 window.onload=jspellInit;

 /*****************************************************/
 /* Implement this function to explicitly declare the */
 /* fields that you want to spell check.              */
 /*****************************************************/
 function getSpellCheckArray()
 {
 var fieldsToCheck=new Array();
 // Use DOM Element IDs to specify fields to spell check
 fieldsToCheck[fieldsToCheck.length]=[document,"P5_EFF_DETAILS"];
 fieldsToCheck[fieldsToCheck.length]=[document,"P5_EFF_ACTIVITY"];
 return fieldsToCheck;
 }

 //--> </script>

The problem is that Jspell evolution replaces the standard form elements with some of its own, so we need to re-sync Jspell’s items with the standard APEX ones. Fortunately Jspell provides the means to do this.

We need to change any buttons that do a “save”, adding some extra javascript in.

The following needs to changed for your submit/save button;

And for your “create” button.

I’ve tested Jspell evolution and it appears to work and re-syncs as expected but I’m going with the HTML version in production.

Links

Advertisement


No Responses Yet to “Apex spell checker”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.