1

Using mojarra 2.1.27 and richfaces 4.3.6 on tomcat7, I was trying to implement my own exception handler for the ajax requests (Following all your advices) but I never get access to the render exception.

I have normal postback exceptions handled through web.xml <error-page> directives, which works fine, and ajax request should go through my custom handler. This seems to work when updating values and invoking the actions, but not with exceptions during rendering phase.

Having this simple ajax command button

<a4j:commandButton execute="@this" action="#{testController.actionButton4}"
    render="@form" value="Ajax Post + Render Error"/>

which (amongst others) renders a div with a result

<div id="result">
  #{testController.result}
</div>

Is backed by a simple action in my TestController

public String actionButton4() {
  result = "action4";
  inError = true;
  return null;
}

And a simple getter which is used during the render.

public String getResult() {
  if (inError) {
    inError = false;
    throw new RuntimeException("Render error in " + result);
  }
return result;
}

My handler does more or less the default behaviour

 public void handle() throws FacesException {
   dohandle();
   getWrapped().handle();
 }

 public void dohandle() throws FacesException {
   FacesContext fc = FacesContext.getCurrentInstance();
   PhaseId phaseId = fc.getCurrentPhaseId();
   boolean partialRequest = fc.getPartialViewContext().isPartialRequest();
   boolean ajaxRequest = fc.getPartialViewContext().isAjaxRequest();
   Iterator<ExceptionQueuedEvent> iterator = getUnhandledExceptionQueuedEvents().iterator();

   log.trace("Phase id ({})", phaseId);
   while (iterator.hasNext()) {
      log.trace("Request is partial ({}). Request is ajax ({})", partialRequest, ajaxRequest);
      if (!ajaxRequest) {
         return;
      }
      ...
   }
 }

What I see during rendering is a logging exception in the ExtendedPartialViewcontextImpl of richfaces

Jun 25, 2014 10:18:44 AM org.richfaces.context.ExtendedPartialViewContextImpl$RenderVisitCallback logException
SEVERE: /test2.xhtml: Error reading 'result' on type c.n.g.w.controller.TestController
...

Then I see the phase ends and the exception handler is consulted

10:18:44.336 {http-bio-8080-exec-2} TRACE c.n.g.w.generic.LifeCycleListener - END PHASE RENDER_RESPONSE 6
10:18:44.336 {http-bio-8080-exec-2} TRACE c.n.g.w.generic.ExceptionHandler - Phase id (RENDER_RESPONSE 6)

But for some reason there is no unhandled exception in the queue.

I couldn't find anything stating that the RF rendering should react any different that others, but I suspect it could be. Does anyone know more than me here?

UPDATE:

I notice from the client side log that the rendered output is clipped right at the EL tag, so the rendering breaks and commits the partial result for some reason.

Niels Bech Nielsen
  • 4,777
  • 1
  • 21
  • 44
  • This response should answer your question as well: http://stackoverflow.com/questions/15610974/jsf-2-0-custom-exception-handler-throws-illegalstateexception-on-handlenavigatio/15612391#15612391 – Andrey Jun 27 '14 at 08:19
  • Thanks for replying. I saw that post, but it doesn't help as I can't work with the exception, be it partially responded or not. Actually I have tried to increase the buffer size, but it has been futile so far – Niels Bech Nielsen Jun 27 '14 at 08:21
  • Haven't tried without richfaces (yet). But, what I see is when the exception handler is consulted after render phase, there is no handled or unhandled exception in the exception queue. I must assume RF have dealt with it internally somewhere. – Niels Bech Nielsen Jul 01 '14 at 08:00
  • I tried swapping Primefaces in, and it appears to drop the exception in the unhandled queue (as I would expect). However, it appears that Primefaces doesn't like my subsequent rendering (setting a new view root and set render all on partialViewContext as per some post of yours) – Niels Bech Nielsen Jul 01 '14 at 08:34
  • I know what you meant. Yes, I concur that it is only RichFaces. Is there some way to hook into their rendering engine to understand why it swallows the exception and just cuts the output? – Niels Bech Nielsen Jul 02 '14 at 10:39
  • This could be related to https://issues.jboss.org/browse/RF-12897 – Martin Höller Oct 16 '14 at 14:34

0 Answers0