4

I tried the AjaxExceptionHandler of omniFaces (which is quite helpful) and configured it to catch java.lang.Throwable and exception stemming from all kind of requests (not only ajax requests).

It works great, however it does not catch javax.el.PropertyNotFoundException when a developer misspelled an EL expression.

So the question is: How to handle javax.el.PropertyNotFoundException with ExceptionHandlerFactory mechanism of JSF2?

Daniel
  • 36,833
  • 10
  • 119
  • 200
jonnie119
  • 421
  • 1
  • 6
  • 16

1 Answers1

2

The FullAjaxExceptionHandler should be able to handle it. Your concrete problem is probably caused because you've a relatively large page which overflowed Facelets' default buffer size of 2KB and thus the response is already committed at the point the exception is been thrown. When a response is committed, a part of the response has already been sent to the client side. There is no way to take the already sent bytes back and present a new response with the error page. You would have exactly the same problem when not using ajax. The exception will instead get logged and the client will stuck with a halfbaked page.

You may want to increase the default response buffer size to about the size of your largest HTML response. This way the response will be generated and buffered fully in server's memory before the first byte get sent to the client side. You can set it by the javax.faces.FACELETS_BUFFER_SIZE context param in web.xml with the buffer size in bytes as value. The following example sets it to 64KB.

<context-param>
    <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
    <param-value>65535</param-value>    
</context-param>

You may want to set this in development/testing environment only so that any mistakes in the view side can be spotted and the live environment can keep using the default buffer size to save server memory.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Strange enough I see the exception in the server log, before the exception handler runs. For other exceptions this does not happen. So I see the `PropertyNotFoundException` twice, once before the exception handler and then the exception handler logs it with this line `context.getExternalContext().log(String.format(LOG_EXCEPTION_OCCURRED, errorPageLocation), exception);` Also I don't see a half-baked page, I just get the background of the application with no menu (but all JSF resources (*.css, *.js) loaded). Is it helpful to mention that this happens with MyFaces and IBM WAS8? – jonnie119 May 09 '12 at 06:55
  • That **is** a halfbaked page. Rightclick and *View Source* in browser. The retrieved HTML response is incomplete because it was been aborted due to this exception. – BalusC May 09 '12 at 11:08
  • I deployed a test application on JBoss and switched between Mojarra and MyFaces; both worked fine and your exception handler handled it perfectly! However increasing the buffer size did not help on Websphere AS. So this issue is rather a setting within our application or a general setting in WAS8 i don't know yet. I'll post further findings – jonnie119 May 09 '12 at 19:42
  • Thank you for the feedback. I don't have WAS8 at hands right now, so I couldn't investigate. Have you also tested on WAS CE? This is freely available. – BalusC May 09 '12 at 19:54
  • @BalusC WAS CE unfortunately is a completely different server. It's Geronimo rebranded by IBM. – Mike Braun Jun 10 '12 at 07:08