Hia mark since you are directly on the response writer anyway, look at the ajax protocol it has an <error> part where you can drag in errors which are pushed into the ajax error listener queue automatically:

<partial-response>
<error>
<error-name>...</error-name>
<error-message>...</error-message>
</error>
</partial-response>

thats how it looks the error then is issued and an error listener is triggered.
The partialResponseWriter should have a startError element afair.


Werner



Am 23.06.10 18:56, schrieb Mark Li:
Hi everyone,

There is any solution for Ajax Error Handler? the 
"org.apache.myfaces.ERROR_HANDLER" seems dont work.


The following is my temp solution:

I hack the code about ajax exception handler. because I try the error handler 
extension, it doesnot work for ajax. and I cant find out any extension point 
either.

there is my code:
org.apache.myfaces.renderkit.ErrorPageWriter
{
.....
public static void handleThrowable(FacesContext facesContext, Throwable ex) 
throws FacesException
{
...

if(!ajaxErrorHandlerInited){
        try {
                String ajaxErrorHandlerString = 
facesContext.getExternalContext().getInitParameter("org.apache.myfaces.AJAX_ERROR_HANDLER");
                if(ajaxErrorHandlerString != null){
                        Class<?>  handler = 
ErrorPageWriter.class.getClassLoader().loadClass(ajaxErrorHandlerString);
                        ajaxErrorHandler = handler.newInstance();
                        ajaxErrorHandlerMethod = 
ajaxErrorHandler.getClass().getMethod("handleException", FacesContext.class,    
     
                }
        } catch (Throwable e) {
                e.printStackTrace();
        } finally{
                ajaxErrorHandlerInited = true;
        }
}

if(ajaxErrorHandler != null){
        try {
                String message = (String) 
ajaxErrorHandlerMethod.invoke(ajaxErrorHandler, facesContext, ex);
                partialWriter.write(message);
        } catch (Throwable e) {
                e.printStackTrace();
                if(ex.getCause() == null)
                        partialWriter.write(ex.getCause().toString());
                else
                        partialWriter.write(ex.getMessage());
        }       
}else{
        if (ex.getCause() != null)
        {
                partialWriter.write(ex.getCause().toString());
        }
        else
        {
                partialWriter.write(ex.getMessage());
        }
}

...
}
.....

}

you can see I define a new "org.apache.myfaces.AJAX_ERROR_HANDLER" parameter 
for myfaces. myfaces or specification should have this feature.

Best Regard

Mark




Reply via email to