IE7 evalScripts with Prototype throws an error

Thursday, May 22nd, 2008

This is yet anther IE bug I have found whilst doing a lot of AJAX stuff with prototype recently. If you make and AJAX request such as AJAX.Update(blah blah and you set evalScripts: true then IE7 will throw a wobbly (great).

Basically if the JS has comments around it then IE blows up. I found this a useful link:

When using Ajax.Updater with the option evalScripts:true like:

  new Ajax.Updater( table_id+'tbody', '/someurl', {
    parameters : { 'table_id':table_id },
    evalScripts : true
  });

and response of /someurl contains the following script:

<script language="JavaScript" type="text/javascript">
<!--
alert( 'Hello' );
// -->
</script>

IE7 throws an error “Syntax error” in line 212 of prototype.js version 1.5.0 in function evalScripts.

If you try a non-commented script like:

<script language="JavaScript" type="text/javascript">
alert( 'Hello' );
</script>

it works. Firefox works whether the script is commented or not.

I am currently using JSF and Facelets for my web app that adds the comments around the JS for you - PAIN IN &^%$£

Not got a solution yet for JSF!

UPDATE!!

We tried to change myFaces so that it did not render the comments but thought that it was a bad idea and back tracked!

So the fix had to be in the JavaScript. We added the following to the Prototype class:

exec: function(code) {
  if ((code += '').blank()) return;
  var script;

  if (document.body) {
    script = new Element('script', { type:'text/javascript' });
    try {
      script.appendChild(document.createTextNode(code));
    } catch (e) { script.text = code; }
    ($$('head').first() || $(document.documentElement)).insert(script);
  }
  else {
    var scriptId = '__prototype_exec_script';
    document.write('<script id="'+ scriptId +'" type="text/javascript">'+ code +'<\/script>');
    script = $(scriptId);
  }
  script.remove();
  script.text = '';

},

And then changed where it evals the scripts to use this method instead. This does mean we cannot easily just upgrade the version of prototype we are using but to be honest I would rather it worked in the first place!

Phase listeners run twice JSF

Thursday, April 17th, 2008

This is a bit of an odd one. A phase listener will run twice only if you tell it! That’s right a computer only does what you tell it!

One common problem with JSF is that you install a phase listener and it runs twice for each phase (that is 4 times for each phase – two invocations of the beforePhase method and two invocations of the afterPhase method). Why and how to solve it?

If you look at the JSF specification (JSF 1.1) on section 10.3.2 the application startup behavior is defined, and it says that the JSF must process zero or more configuration resources using the following algorithm:

  1. All resources named ‘META-INF/faces-config.xml’ in the ServletContext resource path of this webapp.
  2. Check for the ‘javax.faces.CONFIG_FILES’ initialization parameter (that is a context parameter in the web.xml file). If exist treat it as a comma-delimited list of context relative resource paths. And load each resource.
  3. Check for the existing of a web application configuration resource named ‘/WEB-INF/faces-config.xml’. And load it.

Now when we first start a new JSF webapp application we create it with a configuration resource named WEB-INF/faces-config.xml, and then at the web.xml file we announce this configuration resource:

http://www.jroller.com/eyallupu/category/Web-Container

hibernate again

Thursday, March 20th, 2008

http://www.hibernate.org/hib_docs/reference/en/html/tutorial.html

jsf, hibernate and faces

Thursday, March 20th, 2008

http://wiki.apache.org/myfaces/Hibernate_And_MyFaces

JSF Life cycle - what hapens and when

Tuesday, March 18th, 2008

http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

JSF pageContext - think I might need this!

Friday, February 22nd, 2008

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/PageContext.html

JSF - I just want it to work like .NET! Just an event like Page_Load please!

Friday, February 22nd, 2008

http://forum.java.sun.com/thread.jspa?threadID=541382&forumID=427

- useful: ${pageContext.request.contextPath}

JSF - Yes thats right I am doing Java now!

Thursday, February 21st, 2008

http://www.coreservlets.com/JSF-Tutorial/