I have a modal with a form, and what I want is first to close the modal from bean (method "cerrarModal") and after execute the AJAX that makes the insert in database (method "crearUsuario"). I saw this question but it didn't work for me. this is my button:
<b:commandButton value="Guardar" ajax="true"
update="formTblUsuarios:growlMsg formTblUsuarios:tblUsuarios rowModal"
id="btnGuardarUsuario" look="primary"
onclick="ajax:admUsuariosBean.cerrarModal();admUsuariosBean.crearUsuario()" />
And these are my bean methods:
public void cerrarModal() {
RequestContext.getCurrentInstance().execute("$('#usuarioModal').modal('hide');");
}
public void crearUsuario() {
try {
if (this.fachada.crearUsuario(getUsr())) {
this.reestablecerClave();FacesMessages.info("User created.");
} else {
FacesMessages.warning("The user was not created.");
}
} catch (Exception e) {
FacesMessages.error("The user was not created.");
}
But server throws this error:
abr 04, 2018 11:02:14 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
ADVERTENCIA: Failed to parse the expression [#{admUsuariosBean.cerrarModal();admUsuariosBean.crearUsuario()}]
javax.el.ELException: Failed to parse the expression [#{admUsuariosBean.cerrarModal();admUsuariosBean.crearUsuario()}]
at org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:145)
at org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:171)
at org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:216)
at org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:66)
at net.bootsfaces.component.ajax.AJAXBroadcastComponent.evalAsValueExpression(AJAXBroadcastComponent.java:74)
at net.bootsfaces.component.ajax.AJAXBroadcastComponent.executeAjaxCalls(AJAXBroadcastComponent.java:123)
at net.bootsfaces.component.ajax.AJAXBroadcastComponent.broadcast(AJAXBroadcastComponent.java:52)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.abcpagos.otis.beans.Filtro.doFilter(Filtro.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.el.parser.ParseException: Encountered " "; "" at line 1, column 32.
Was expecting one of:
"}" ...
"." ...
"[" ...
">" ...
"gt" ...
"=" ...
"ge" ...
"
I'm using BootsFaces 1.2.0, with PrimeFaces 6.1, JSF 2.2, (XAMPP) Apache Tomcat 7.0.56.Thanks.
First of all, the answer of #Holger is (mostly) right: your particular use case doesn't require an AJAX call. However, there are use cases requiring two successive AJAX calls, so I'll ask your original question nonetheless.
I've implemented the parser of BootsFaces in a very simple way. The onclick handler may consist of three parts: a JavaScript part that's executed before the AJAX call, the AJAX call, and a second JavaScript part that's executed after sending the AJAX request to the server. Note that the second JavaScript bit is almost certainly executed before the Java code.
In theory, I could have implemented the AJAX engine with multiple AJAX calls in mind. However, I didn't see the point to do so: It's easier to call a Java method calling two methods instead of triggering two AJAX calls, each calling a Java method and each updating the DOM.
But then... never say never. If you really need two consecutive AJAX calls, you can implement this using <b:remoteCommand>. Such a <b:remoteCommand> is a JavaScript function calling a Java method via AJAX and updating the DOM. So you can call the <b:remoteCommand> in the onComplete handler to trigger the second AJAX request.
There's that. However, you simply want to close the modal, so I recommend to implement it like so:
<b:commandButton value="Guardar"
update="..."
onclick="$('#usuarioModal').modal('hide');ajax:admUsuariosBean.crearUsuario()" />
You don't need the bean to close the modal form.
<b:commandButton value="Guardar" ajax="true"
update="formTblUsuarios:growlMsg formTblUsuarios:tblUsuarios rowModal"
id="btnGuardarUsuario" look="primary"
actionListener="#{admUsuariosBean.crearUsuario()}"
oncomplete="$('#usuarioModal').modal('hide')"
/>
Related
I have a spring backed form with a model object Foo that contains Bar
<form action="#" th:action="#{/some/action}" th:object="${foo}" method="post">
now, I would like to do something like this:
<input type="text" id="bar.createdAt" name="bar.createdAt" th:value="*{bar.createdAt} ? ${#dates.format(bar.createdAt, #messages.msg('app.dateformat.datetime'))}"/>
but the following parsing exeption is thrown:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#dates.format(bar.createdAt, #messages.msg('app.dateformat.datetime'))" (registration:93)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#dates.format(bar.createdAt, #messages.msg('app.dateformat.datetime'))" (registration:93)
org.thymeleaf.spring4.expression.SpelVariableExpressionEvaluator.evaluate(SpelVariableExpressionEvaluator.java:161)
org.thymeleaf.standard.expression.VariableExpression.executeVariable(VariableExpression.java:154)
org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:59)
root cause
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 7): Property or field 'createdAt' cannot be found on null
org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:211)
org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43)
org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:341)
I've already tried:
...#dates.format(*{bar.createdAt}..., ...#dates.format(__*{bar.createdAt}__...but none has worked out.
the same without the form (directly accessing view model object) works fine.
Any idea what would be the right construct?
Thanks in advance!!!
Instead of :
${#dates.format(bar.createdAt, #messages.msg('app.dateformat.datetime'))}
Change it to :
*{#dates.format(bar.createdAt, #messages.msg('app.dateformat.datetime'))}
So that the utility object will work on the bar property of the last selected object which is the form backing object, ${foo}, in your case.
I think the clue is in the line:
Property or field 'createdAt' cannot be found on null
Are you sure that bar is not null?
We have a JSF 2.0, Primefaces 5.0, Spring Security 3.2.3.RELEASE application.
To handle session timeout, I am using primefaces idleMonitor and p:dialog & javascript to display a countdown popup and redirect them back to login page.
I have also implemented a custom CacheControlPhaseListener so that the pages are not cached. I set the no-cache in the response headers in the CacheControlPhaseListener.
<lifecycle><phase-listener id="nocache">com..filter.CacheControlPhaseListener</phase-listener></lifecycle>
I also have error handling configured in my web.xml:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/error.jsf</location></error-page>
I have also implemented a ViewExpiredHandler that extends ViewHandlerWrapper
#Override
public UIViewRoot restoreView(FacesContext ctx, String viewId)
{
UIViewRoot viewRoot = super.restoreView(ctx, viewId);
try
{
if (viewRoot == null)
{
viewRoot = super.createView(ctx, viewId);
ctx.setViewRoot(viewRoot);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return viewRoot;
}
The problem I am still having is:
1. When the session expires on a idle page (E.g. Search page) and if some ajax action is triggered on a page, even though I logout, when I navigate back to the page (e.g. Login-> Home-> Search page). I see a partial-response xml error:
<partial-response><changes><update id="blGridId"><table id="blGridId" style="width:100%;">
<tbody>
<tr>
<td><div id="blTableId" class="ui-datatable ui-widget ui-datatable-scrollable ui-datatable-resizable"><div id="sublTableId_paginator_top" class="ui-paginator ui-paginator-top ui-widget-header ui-corner-top" role="navigation"><span class="ui-paginator-prev ui-state-default ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-prev">p</span></span><span class="ui-paginator-next ui-state-default ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-next">p</span></span></div><div class="ui-widget-header ui-datatable-scrollable-header"><div class="ui-datatable-scrollable-header-box"><table role="grid"><thead id="blTableId_head"><tr role="row"><th id="blTableId:j_idt101" class="ui-state-default ui-resizable-column" role="columnheader" style="width:34px; #width:37px;"><span class="ui-column-title"><span style="word-wrap: break-word;white-space: normal;">Client </span></span></th><th id="blTableId:j_idt104" class="ui-state-default
2. If I hit a browser refresh, it loads back the page and I can continue with the actions.
Please let me know what I need to do in addition to the above to resolve the partial-response error. Do I need to add a servlet filter to invalidate the session?
I would really appreciate any help and feedback on this as it is high priority.
I had got the same issue when session had been expired. I thought it was too late, but maybe would be helpful for others who has issues like me.
The root cause is Spring Security saves the last request before redirecting client to do the authentication. After then, Spring security would try to perform the request again when user visits the page of last request. Unfortunately, the request was ajax/partial and its view was expired -> partial xml content was returned.
Easy way to get rid of this issue is removing the saving behavior of Spring Security. SavedRequestAwareAuthenticationSuccessHandler class is used to handle these kind of behaviours. Configure as:
<bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:authenticationManager-ref="authenticationManager"
p:authenticationFailureHandler-ref="authenticationFailureHandler"
p:authenticationSuccessHandler-ref="authenticationSuccessHandler"
p:usernameParameter="username"
p:passwordParameter="password">
</bean>
...
<bean id="authenticationSuccessHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"
p:defaultTargetUrl="/"
p:alwaysUseDefaultTargetUrl="true"/>
Hope it would help.
I have a protected page that is supposed to redirect to the login screen when not logged in. The issue is that when i try to view that page, instead of redirecting to login it crashes with a IllegalStateException error. The kicker is that if I manually visit the login page it loads, then I try to visit the protect page again and it will redirect as expected. It must be some sort of session caching issue because the problem will never happen again unless i restart the browser. After a browser restart the issue will continue until I manually visit the login page again. And of course the error reporting is super vague to what the issue actually is
Aug 20, 2013 4:36:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:852)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:127)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
My Interceptor that I use to validate if they are logged in and redirect when neccessary. the very first return BaseAction.Login hits like its supposed to, and when I enable logging the struts2 loggers indicate a redirect to viewLogin is going to happen, but it doesn't. I just crashes instead:
public String intercept(ActionInvocation invocation) throws Exception {
BaseAction action = (BaseAction)invocation.getAction();
LoginManager loginManager = (LoginManager)action.getSession().get("loginManager");
Boolean loggedIn = false;
final ActionContext context = invocation.getInvocationContext();
ActionMapping mapping = (ActionMapping)context.get(ServletActionContext.ACTION_MAPPING);
if(loginManager == null && action.isLoginRequired()) {
//user is not logged in and login required, redirect them to login module
return BaseAction.LOGIN;
} else if(loginManager != null && action.isLoginRequired()) {
//logged in, make sure they are accessing a valid resource
String loginKey = action.getSessionLoginVarable(mapping);
if(loginManager.getLoginPaths().containsKey(loginKey)) {
return invocation.invoke();
} else {
//return to login which will redirect them to appropriate path
return BaseAction.LOGIN;
}
} else {
//public access to continue with action
return invocation.invoke();
}
}
Struts-config file
<package name="student" namespace="/student" extends="struts-default-custom">
<default-action-ref name="viewLogin" />
<global-results>
<result name="login" type="redirectAction">viewLogin</result>
</global-results>
<action name="*Login" method="{1}" class="controller.shared.StudentLogin">
<interceptor-ref name="noLoginStack"/>
<result type="redirectAction">viewSearchAdvisors</result>
<result name="input">/student/student-login.jsp</result>
<result name="error" type="redirectAction">viewLogin</result>
</action>
So just to summaraize. First visit to this protected page on browser startup it crashes instead of redirect to login. I manually visit login page, then try to visit protected page no crash and it redirects back to login like its supposed to. It will continue to work fine until i restart the browser.
any ideas??
This issue is resolved. I have absolutely no idea why, but when I changed my struts xml files to use this DTD file
http://struts.apache.org/dtds/struts-2.3.dtd
instead of
http://struts.apache.org/dtds/struts-2.1.dtd
the issue went away. I was grasping at straws checking every configuration file against config files of other apps i have that use the same process without issue and saw this. I decided what the hell and made the change...and it works.
My preRenderView event invokes OmniFaces Ajax utility's oncomplete() method to execute javascript on the client. I just tested this, and the javascript is not executed on the client.
My f:event is below.
<f:metadata>
<o:enableRestorableView/>
<f:event type="javax.faces.event.PreRenderViewEvent" listener="#{pageNavigationController.preRenderView()}"/>
</f:metadata>
My pageNavigationController.preRenderView() is below,
public void preRenderView() {
if (initLayoutForPage) {
// initialize layout for page
layoutController.initializeForPage(page);
initLayoutForPage = false;
}
if (usersController != null) {
usersController.preRenderView();
}
}
which calls usersController.preReviewView() below, which invokes Ajax utility's oncomplete().
public void preRenderView() {
Ajax.oncomplete("document.getElementById('menuBarForm:btnLogout').click();");
}
Currently in production, the javascript above works as designed; this javascript is called as follows.
<script>window.onbeforeunload = function() { document.getElementById('menuBarForm:btnLogout').click(); }</script>
So, why is the javascript not being executed on the client?
EDIT: I no longer need this functionality as I just figured out a workaround for the original problem, but I would appreciate an answer to this question. Thanks. :)
I just confirmed that Ajax.oncomplete() works as designed even when executed during/via preRenderView event. OmniFaces 'Ajax' utility is for 'Ajax' requests. I was under the assumption that OmniFaces Ajax.oncomplete() would send javascript to client during preRenderView on a FPR (full page refresh or non-AJAX request).
I set up my web app as follows:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/WEB-INF/include/viewExpired.html</location>
</error-page>
so that the above error page be displayed when the viewExpiredException is thrown.
However, when I restart the server and submit an ajax request on an "left-open" page, the exception is thrown in the console and my error page is not displayed.
Here is that stack trace from the console:
javax.faces.application.ViewExpiredException: viewId:/contact.jsf - La vue /contact.jsf na pas pu être restaurée.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:200)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.jeanbaptistemartin.util.DisableUrlSessionFilter.doFilter(DisableUrlSessionFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
anyone has got any clue please?
Thanks in advance,
J.
So you want to handle Ajax errors on the standard JSF 2.0 implementation? The standard JSF implementation doesn't provide a ready-to-use component for this. In PrimeFaces for example, you could use <p:ajaxStatus> component for this. The JSF 2.0 specification however outlines the following in chapter 13.3.6.2:
13.3.6.2 Handling Errors For All Ajax Requests
The JavaScript API provides the jsf.ajax.addOnError function that can be used to register a JavaScript function that will be notified when an error occurs for any Ajax request/response. Refer to Section 14.4 “Registering Callback Functions” for more details. The jsf.ajax.addOnError function accepts a JavaScript function argument that will be
notified when errors occur during any Ajax request/response cycle. [P1-start-event] The implementation must ensure the
JavaScript function that is registered must be called in accordance with the errors outlined in Section TABLE 14-5
“Errors”
You can find here a blog of one of the Mojarra developers which contains basic examples how to show the ajax status. Here's an extract of relevance:
<h3> Status:</h3>
<textarea id="statusArea" cols="40" rows="10" readonly="readonly" />
A simple textarea, not even hooked
into the backend server data model.
Then in our javascript (for the demo,
in a separately loaded file, though it
could just as easily be in page) we
have:
var statusUpdate = function statusUpdate(data) {
var statusArea = document.getElementById("statusArea");
var text = statusArea.value;
text = text + "Name: "+data.source.id;
if (data.type === "event") {
text = text +" Event: "+data.name+"\n";
} else { // otherwise, it's an error
text = text + " Error: "+data.name+"\n";
}
statusArea.value = text;
};
// Setup the statusUpdate function to hear all events on the page
jsf.ajax.addOnEvent(statusUpdate);
jsf.ajax.addOnError(statusUpdate);
You could it as well to redirect to an error page using JS.
window.location = '/errors/500.xhtml';