Reputation: 1
I have written the following code in our xhtml file , for redirecting to error page for ajax calls, I have written it in common page.
var onError = function onError() {
window.location = 'http://' + jQuery(location).attr('host')+'/saec/app/error';//saec/app/error };jsf.ajax.addOnError(onError);
It is working fine fine , but in browser am getting the error as "Jsf undefined".
I have tried it by including the
h:outputScript name="jsf.js" library="javax.faces" target="head"
also but its giving the same error.
Can any one Please tell me where I did the mistake
Upvotes: 0
Views: 3446
Reputation: 1108782
but in browser am getting the error as "Jsf undefined".
Are you sure that this isn't a typo from your side? It's jsf
in all lowercase, not Jsf
.
In any case, you will get this error whenever you try to reference the jsf
object before it is ever been declared in JavaScript context. For example, when the generated HTML output (as you can see by View Source in webbrowser) look like this:
<script>jsf.ajax.addOnError(functionName);</script>
<script src="/contextname/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"></script>
You should make sure that you reference it after it is been declared:
<script src="/contextname/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"></script>
<script>jsf.ajax.addOnError(functionName);</script>
Also, you need to take into account the fact that JSF will only auto-include it whenever there's a <f:ajax>
tag elsewhere in the view. You might want to add an extra check if this is the case or not:
if (typeof jsf !== 'undefined') {
jsf.ajax.addOnError(functionName);
}
Otherwise, you need to add the following line to make absolutely sure that JSF will auto-include the ajax script on every request even though the view doesn't contain any <f:ajax>
.
<h:outputScript library="javax.faces" name="jsf.js" target="head" />
Unrelated to the concrete problem, if you'd like to use the standard <error-page>
mechanisms in web.xml
on ajax requests as well, then consider using this FullAjaxExceptionHandler
instead.
Upvotes: 2