-
1. Re: When use a4j.ajax,How to catch Exception and show it on pages?
boy18nj Apr 9, 2011 8:25 PM (in response to maxim_rong)refer to, how to use javascript to handle exceptions. Use try block outside login and catch the exception. here you go. Since you know your exception very well, handle at your convenience and take appropriate action.
A4J.AJAX.onError is generally used when there is an error in ajax response...example to handle view expiration or no response from server.
-
2. Re: When use a4j.ajax,How to catch Exception and show it on pages?
maxim_rong Apr 9, 2011 10:02 PM (in response to boy18nj)hi, Aman!
i just tried use try catch outside login (js), but i can't catch the exception from action.
and i just want to know how to catch the exception in ajax response.
so i try to user A4J.AJAX.onError.
but it said A4J is not defined,
Whether i need to include some js file?
or there is some other way to catch exception from action.(via jsf2 or richfaces)
-
3. Re: When use a4j.ajax,How to catch Exception and show it on pages?
lurker_huang Apr 13, 2011 9:34 PM (in response to maxim_rong)I have the same problem too.
please help~!!!
-
4. When use a4j.ajax,How to catch Exception and show it on pages?
maxim_rong Apr 14, 2011 3:38 AM (in response to boy18nj)hi
i want to catch the exception msg from action, and alert is in js.like "
throw new Exception("test!!")";
could you gave me an example??
-
5. When use a4j.ajax,How to catch Exception and show it on pages?
ilya_shaikovsky Apr 15, 2011 10:10 AM (in response to lurker_huang)Client side
1) http://javaserverfaces.java.net/nonav/docs/2.0/jsdocs/symbols/jsf.ajax.html#constructor
2) RichFaces components provides onerror handler at component level additionally.
Server Side
Read about JSF 2 exception handling there http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/ and there http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/context/ExceptionHandler.html and also could check some JSF 2 reference for real samples.
-
6. Re: When use a4j.ajax,How to catch Exception and show it on pages?
maxim_rong Apr 22, 2011 6:13 AM (in response to ilya_shaikovsky)thx a lot,
but i'm sorry that i can't access page which your provided.because my country's net is limit.
this problem i have done by myself, and i show my solutions.
first, custom the jsf's exception handler and config your exception handler in faces-config.xml.
and you need write two class,
one is ExceptionHandldFactory and it must extends ExceptionHandlerFactoryImpl.
follow is my Class:
{code}
package com.agile.sys.exception;
import javax.faces.context.ExceptionHandler;
import com.sun.faces.context.ExceptionHandlerFactoryImpl;
public class ExceptionHandlerFactory extends ExceptionHandlerFactoryImpl {
private final javax.faces.context.ExceptionHandlerFactory parent;
public ExceptionHandlerFactory(javax.faces.context.ExceptionHandlerFactory parent) {
this.parent = parent;
}
@Override
public ExceptionHandler getExceptionHandler() {
ExceptionHandler result = parent.getExceptionHandler();
result = new CustomExceptionHandler(result);
return result;
}
}
{code}
then you need config this class in your faces-config.xml.(even in jsf2, you also need to do this):
{code:xml}
<factory>
<exception-handler-factory>com.agile.sys.exception.ExceptionHandlerFactory</exception-handler-factory>
</factory>
{code}
second, you need to write another Class:
{code}
package com.agile.sys.exception;
import java.util.Iterator;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerWrapper;
import javax.faces.context.FacesContext;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
public class CustomExceptionHandler extends ExceptionHandlerWrapper {
private final ExceptionHandler parent;
public CustomExceptionHandler(ExceptionHandler parent) {
this.parent = parent;
}
@Override
public ExceptionHandler getWrapped() {
return this.parent;
}
@Override
public void handle() throws FacesException {
// todo you exception handler, follow is mine, i add the exception to Message.
for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
ExceptionQueuedEvent event = i.next();
ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();
FacesContext.getCurrentInstance().addMessage("",
new FacesMessage(FacesMessage.SEVERITY_ERROR, t.getMessage(), t.getMessage()));
}
// getWrapped().handle();
}
}
{code}
the last, in your pages, you can use the <h:messages>, it can show your exception.
my English is not good, i hope i expressed clearly,
-
7. Re: When use a4j.ajax,How to catch Exception and show it on pages?
ilya_shaikovsky Apr 22, 2011 6:47 AM (in response to maxim_rong)Great to hear that you solved it!