Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can cause "jsf is not defined" error in browser console

Hi I got a simple fresh project based on MyFaces 2.0.11 with Primefaces 3.0 on Tomcat 6

When I'm trying to navigate to a page I'm getting Uncaught ReferenceError: jsf is not defined error which directs me to a ref in my js code jsf.ajax.addOnEvent ... (which is reasonable cause I'm trying to use the jsf.js and it's not event present I'm my page..)

And if I do view source of my page I dont the the include of the jsf.js file

Now if I add it manually like this

<h:outputScript name="jsf.js" library="javax.faces" target="head"/>

every thing works just fine... but I prefer not to include it manually , Instead I would like to know what are the reasons that can cause the lack of the jsf.js in my page

I google for a while and none of the similar case represents mine

I do have <h:head> and <h:body> My page is really simple...

Any Ideas?

like image 284
Daniel Avatar asked Apr 02 '12 06:04

Daniel


1 Answers

This script will only be auto-included whenever you use <f:ajax> in the view. If you don't, then it won't be auto-included.

Just add an extra check before you call jsf.ajax.addOnEvent:

if (typeof jsf !== 'undefined') {
    jsf.ajax.addOnEvent(someFunctionName);
}

Or, explicitly include the library by <h:outputScript> on the proper library, like as you already did.

like image 54
BalusC Avatar answered Oct 03 '22 15:10

BalusC