QeelwaEtech / omnifaces

Automatically exported from code.google.com/p/omnifaces
0 stars 1 forks source link

How to do FullAjaxExceptionHandler aware of error codes? #176

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
OmniFaces 1.4.1

Some exceptions, such as SQLException has an error code (getErrorCode() with 
int or Enum as return value). How to do FullAjaxExceptionHandler aware of error 
codes? I know, it doesn't work, but I would like to have something like in 
web.xml or an external config. file:

<error-page>
  <exception-type>ip.commons.exceptions.ServiceException</exception-type>
  <exception-code>ACCESS_DENIED</exception-code>
  <location>/sections/errorpages/accessDenied.jsf</location>
</error-page>

<error-page>
  <exception-type>ip.commons.exceptions.ServiceException</exception-type>
  <exception-code>OBJECT_NOT_FOUND</exception-code>
  <location>/sections/errorpages/objectNotFound.jsf</location>
</error-page>

etc.

Have you already thought about to do FullAjaxExceptionHandler more flexible? 
How to extend FullAjaxExceptionHandler? I would overwrite the method which 
handles an exception of a certain type (to distinguesh error codes, e.g.), but 
I can not see this possibility.

Thanks in advance.

Original issue reported on code.google.com by ovarak...@googlemail.com on 13 May 2013 at 10:29

GoogleCodeExporter commented 9 years ago
So, my proposal is to do a method 
WebXml.INSTANCE.findErrorPageLocation(exception) overwritable. You could add 
this method to the FullAjaxExceptionHandler.java

protected String findErrorPageLocation(WebXml webXml, Throwable exception)

und change the call WebXml.INSTANCE.findErrorPageLocation(exception) to 
findErrorPageLocation(WebXml.INSTANCE, exception).

This will allow to overwrite findErrorPageLocation(...) in a custom 
ExceptionHandler. I could write e.g. in web.xml

<exception-type>ip.commons.exceptions.ServiceException?code=ACCESS_DENIED</excep
tion-type>

and parse this in a custom ExceptionHandler as I want.

Original comment by ovarak...@googlemail.com on 13 May 2013 at 10:44

GoogleCodeExporter commented 9 years ago
Or nothing overwrite. Simple extend WebXml to be able to parse exceptions in 
this form

<exception-type>ip.commons.exceptions.ServiceException?getErrorCode=ACCESS_DENIE
D</exception-type>

I mean as a built-in feature. "getErrorCode" defines a method in 
ServiceException which should be invoked via Java Reflections.

What do you think?

Original comment by ovarak...@googlemail.com on 13 May 2013 at 10:52

GoogleCodeExporter commented 9 years ago
Makes sense. I will add protected methods for overriding.

Original comment by balusc on 15 May 2013 at 1:47

GoogleCodeExporter commented 9 years ago
Added: 
https://code.google.com/p/omnifaces/source/detail?r=2764ca087e235f5c2ea6ac82d155
06a993440cb7

Attached snapshot contains the changes.

Original comment by balusc on 15 May 2013 at 1:56

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks guys!

Original comment by ovarak...@googlemail.com on 15 May 2013 at 9:26

GoogleCodeExporter commented 9 years ago
I have a question regarding this thread. Has it been implemented in Omnifaces 
1.7 ?
As Oleg specified, can we mention the error code like this :
<exception-type>ip.commons.exceptions.ServiceException?getErrorCode=ACCESS_DENIE
D</exception-type>

If this is possible, it would be really really awsme!
Please clarify on this.
I have a custom exception class, and I tried to specify it as above and it 
complained about ClassNotFoundException (Assuming 
ip.commons.exceptions.ServiceException is my custom exception , something 
similar I mean).

Is it possible to map the error pages with combination of 
exceptionType+exceptionCode!
Help Appreciated!
Thanks!

Original comment by allampal...@gmail.com on 11 May 2014 at 6:02

GoogleCodeExporter commented 9 years ago
No. You have to override the method

findErrorPageLocation(...)

in the FullAjaxExceptionHandler with your custom code. Look this commit 
mentioned above please 
https://code.google.com/p/omnifaces/source/detail?r=2764ca087e235f5c2ea6ac82d155
06a993440cb7

Original comment by ovarak...@googlemail.com on 11 May 2014 at 9:27