Chris' SWI blog

« Previous day (Aug 10, 2008) | Main | Next day (Aug 12, 2008) »

http://blogs.sun.com/chrisf/date/20080812 Tuesday August 12, 2008

JSF - making sure your JSF pages load prior to calling JavaScript methods

Here's a quick note, but I found it very useful when it came to testing FireFox 3 and/or IE 8:

<![CDATA[
  function OnLoad() {
    var ignoreMe = document.body.offsetWidth;

    if (ignoreMe == null) {
       return setTimeout('OnLoad();', 10);
    }

    parent.leftFrame.location.href = "/faces/NavigationPage.jsp";
  }
]]>

Then I add the javascript onLoad method to the JSF body tag (onLoad="OnLoad()") for example:

<webuijsf:body binding="#{com$FirstPage.body1}" id="body1" onLoad="OnLoad();" style="-rave-layout: grid">

That's it, this simple onLoad event makes sure the document has a page width set, if it doesn't I use the timeout method to re-call the OnLoad event and try again.


Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.