Search code examples
jsfprimefacesinternet-explorer-10websphere-8commandlink

SCRIPT5009: 'myfaces' is undefined


I have JSF2 application running on WAS8.5.4 sever using libraries primefaces-3.4-SNAPSHOT-20120807.jar and javax.faces-2.1.9.jar . In one of the pages , I have p:commandlink button to view attached documents .But when users click on this component , the browser displays error SCRIPT5009: 'myfaces' is undefined .As a result, user is not able to view the documents . Please advise how to fix this issue.


Solution

  • WAS ships with MyFaces out the box, yet you're attempting to override it altogether by providing Mojarra via the webapp, apparently without instructing WAS that it should load WAR-bundled JSF instead of WAS-bundled JSF.

    Get rid of javax.faces-2.1.9.jar (that's Mojarra). WAS as being a full fledged Java EE container already ships with JSF out the box (which is MyFaces).

    The error you faced is just a JavaScript error. The JavaScript variable myfaces is nowhere defined. It's usually automatically defined when MyFaces is properly loaded and auto-includes its own jsf.js JavaScript file in the JSF page. The failure can happen when either <h:head> is missing, or when Mojarra's own jsf.js JavaScript is instead being auto-included (you perhaps already know, web resources in WAR have higher loading precedence than those in JARs and the server itself). Mojarra's jsf.js has indeed nowhere a variable name myfaces defined. It's instead mojarra. However, the HTML output of JSF components is being rendered by MyFaces, which was already loaded by the server before the WAR gets chance to load its bundled Mojarra, and therefore they will render and expect the myfaces JavaScript variable (but which is thus nowhere available, as explained).