Wednesday, October 31, 2007

Disabling autocomplete on every single field in Curam

Like disabling the cache, disabling autocomplete is one of the other things that may be requested for Curam applications.  Theoretically this is simple if you control everything in a web application as you only need to put in autocomplete="off" in every form.  However, you can't really do that easily in Curam as you don't control the output JSPs nor do they provide you with a facility to do it.

Modifying gen-jsp.xsl

The first inclination would be to modify the generators just like I did when I disabled the cache. Unfortunately, Curam has its own form tag which does not accept the autocomplete attribute. So changing gen-jsp.xsl will not work.

Curam Implementation

Instead of fixing the output from the generators, we can use JavaScript that gets executed to update all the forms to disable autocomplete.  Of course to do that you need to know how to handle the differences between browsers for the onload and the setAttribute functionality.

However, we can get around it by using the standard Curam extension mechanism.  If you look at the generated code, then you will notice that there are a few JavaScript files that are always loaded, one of the relatively stable ones that have not really changed is omega3-util.js so we can theoretically use that.

First we make a copy of CuramCDEJ\lib\curam\web\jscript\omega3-util.js to components\custom\WebContent\CDEJ\jscript.  That will allow us to separate our customizations from the core files.

Now we write the following script at the end of the file.

function disableautocomplete() {
  var forms = document.getElementsByTagName('form')
  for (var i = 0; i < forms.length; ++i) {
    if (forms[i].setAttribute) {
      forms[i].setAttribute('autocomplete', 'off')
    } else {
      forms[i].autocomplete = 'off'
    }
  }
}
if (window.addEventListener) {
  window.addEventListener('load', disableautocomplete, true)
} else if (window.attachEvent) {
  window.attachEvent('onload', disableautocomplete)
} else {
  window.onload = disableautocomplete
}

Customizing gen-page-footer.xsl does not work

Although this change is be done using JavaScript and the scripts can be placed anywhere including gen-page-footer.xsl, this will not be sufficient.  The gen-page-footer.xsl file is only used by the standard Curam pages, but pop-ups do not use this file so if the pop-up has a form, the data would be saved.

0 comments: