exeption in getter

View: New views
8 Messages — Rating Filter:   Alert me  

exeption in getter

by Liumin Hu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
hi everyone,
 
Sometimes i have the nullpointer excption dans les getters. I think(not sure) the facelet catches these exceptions and show a page with the detail of the exception. I want to know if there is a way to handle this exception by myself and redirect it to another page?
 
thanks in adance
 
liu

Re: exeption in getter

by Dominik Dorn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

you can do this in the web.xml descriptor file...

  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp</location>
  </error-page>
http://weblogs.java.net/blog/crazybob/archive/2004/02/exception_handl.html

kind regards,
Dominik Dorn


On Fri, Jul 10, 2009 at 9:43 AM, liumin HU<lhu@...> wrote:

> hi everyone,
>
> Sometimes i have the nullpointer excption dans les getters. I think(not
> sure) the facelet catches these exceptions and show a page with the detail
> of the exception. I want to know if there is a way to handle this exception
> by myself and redirect it to another page?
>
> thanks in adance
>
> liu

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: exeption in getter

by Liumin Hu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thanks for your reply,

your suggestion works for exception triggered in action(commandbuton by
example.). but not works for exception in getter.

liu

----- Original Message -----
From: "Dominik Dorn" <dominik.dorn@...>
To: <users@...>
Sent: Friday, July 10, 2009 2:50 PM
Subject: Re: exeption in getter


you can do this in the web.xml descriptor file...

  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp</location>
  </error-page>
http://weblogs.java.net/blog/crazybob/archive/2004/02/exception_handl.html

kind regards,
Dominik Dorn


On Fri, Jul 10, 2009 at 9:43 AM, liumin HU<lhu@...> wrote:

> hi everyone,
>
> Sometimes i have the nullpointer excption dans les getters. I think(not
> sure) the facelet catches these exceptions and show a page with the detail
> of the exception. I want to know if there is a way to handle this
> exception
> by myself and redirect it to another page?
>
> thanks in adance
>
> liu

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: exeption in getter

by ghadami :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi liu, in web.xhtml
disable myfaces and faclet errorhandling by context parameters:
 <context-param>
  <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
  <param-value>false</param-value>
 </context-param>
 <context-param>
  <param-name>facelets.DEVELOPMENT</param-name>
  <param-value>false</param-value>
 </context-param>

I prefere to use a Filter to catch uncaught exceptions
@Component //i use spring to automaticly setup my filters from classpath but u can ignore this Line and set u the filter in web.xml


public class ExceptionFilterListener implements Filter{

    @Override
    public void destroy() {}

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
            FilterChain filterChain) throws IOException, ServletException {
        try {
            HttpServletRequest hr = (HttpServletRequest) servletRequest;
            String requestURI = hr.getRequestURI();
            filterChain.doFilter(servletRequest, servletResponse);
           
        } catch (Exception e) {
            HttpServletRequest hr = (HttpServletRequest) servletRequest;
            String requestURI = hr.getRequestURI();
            //The class handling the error and redirecting to my "nice error page"
            //sending some information to the administrator, browser, requestparameter, sessionparameter ...
            //This is done in a extra class, as there are many other places to catch exceptions
            ErrorHandler errorHandler = new ErrorHandler();
            errorHandler.handle(e,"/pages/error.xhtml",requestURI.toString(), servletResponse, servletRequest);
        }
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {  }

}



But I also use a error page configured by web.xml
 <error-page>
  <exception-type>javax.servlet.ServletException</exception-type>
  <location>/pages/error.jsp</location>
 </error-page>


<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<%@page import="com.ibson.errorhandling.ServletExceptionHandler"%>
<%@page isErrorPage="true" %>
<html>
<head></head>
    <body>
    <%
       //The class handling the error and redirecting to my "nice error page"
       //sending some information to the administrator, browser, requestparameter, sessionparameter ...
       //This is done in a extra class, as there are many other places to catch exceptions
        ServletExceptionHandler handler = new ServletExceptionHandler();  
        handler.handle(pageContext,"/pages/error.jsf");
    %>  
    </body>
</html>

best regards
Keywan Ghadami
-------- Original-Nachricht --------
> Datum: Fri, 10 Jul 2009 09:43:24 +0200
> Von: "liumin HU" <lhu@...>
> An: "facelet list" <users@...>
> Betreff: exeption in getter

> hi everyone,
>
> Sometimes i have the nullpointer excption dans les getters. I think(not
> sure) the facelet catches these exceptions and show a page with the detail of
> the exception. I want to know if there is a way to handle this exception
> by myself and redirect it to another page?
>
> thanks in adance
>
> liu

--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: exeption in getter

by Jan-Kees van Andel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey,

I prefer not to get Exceptions in getters. ;-) I think it is an
antipattern to put anything besides a return in a getter. Yeah, I know
about lazy loading tricks using if (var == null { /* initialize */ }
return var;, but my experience is that this leads to spaghetti code
where you don't know if and when some code is executed. I prefer just
putting logic in action methods. The only time this really doesn't
work is when you access pages directly and want to do some
post-processing, but there are other, more elegant, options for this
problem (frameworks for example).

When you only put logic in actions, you can implement a custom
ActionListener (see:
http://developers.sun.com/docs/jscreator/apis/jsf/javax/faces/event/ActionListener.html)
and registering it in your faces-config.xml (see:
http://stackoverflow.com/questions/464193/intercepting-exceptions-with-custom-jsf-event-handlers).

The advantage of using an ActionListener over a Filter is that you can
catch the exception inside the lifecycle. You can do some maintenance,
redirecting to an error page, displaying errors inline in your page
(using FacesContext.addMessage). Also, you don't have to turn off
Facelets and MyFaces development options.

Regards,
Jan-Kees



2009/7/10 Keywan Ghadami <Ghadami@...>:

> hi liu, in web.xhtml
> disable myfaces and faclet errorhandling by context parameters:
>  <context-param>
>  <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
>  <param-value>false</param-value>
>  </context-param>
>  <context-param>
>  <param-name>facelets.DEVELOPMENT</param-name>
>  <param-value>false</param-value>
>  </context-param>
>
> I prefere to use a Filter to catch uncaught exceptions
> @Component //i use spring to automaticly setup my filters from classpath but u can ignore this Line and set u the filter in web.xml
>
>
> public class ExceptionFilterListener implements Filter{
>
>    @Override
>    public void destroy() {}
>
>    @Override
>    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
>            FilterChain filterChain) throws IOException, ServletException {
>        try {
>            HttpServletRequest hr = (HttpServletRequest) servletRequest;
>            String requestURI = hr.getRequestURI();
>            filterChain.doFilter(servletRequest, servletResponse);
>
>        } catch (Exception e) {
>            HttpServletRequest hr = (HttpServletRequest) servletRequest;
>            String requestURI = hr.getRequestURI();
>            //The class handling the error and redirecting to my "nice error page"
>            //sending some information to the administrator, browser, requestparameter, sessionparameter ...
>            //This is done in a extra class, as there are many other places to catch exceptions
>            ErrorHandler errorHandler = new ErrorHandler();
>            errorHandler.handle(e,"/pages/error.xhtml",requestURI.toString(), servletResponse, servletRequest);
>        }
>    }
>
>    @Override
>    public void init(FilterConfig arg0) throws ServletException {  }
>
> }
>
>
>
> But I also use a error page configured by web.xml
>  <error-page>
>  <exception-type>javax.servlet.ServletException</exception-type>
>  <location>/pages/error.jsp</location>
>  </error-page>
>
>
> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
> <%@page import="com.ibson.errorhandling.ServletExceptionHandler"%>
> <%@page isErrorPage="true" %>
> <html>
> <head></head>
>    <body>
>    <%
>       //The class handling the error and redirecting to my "nice error page"
>       //sending some information to the administrator, browser, requestparameter, sessionparameter ...
>       //This is done in a extra class, as there are many other places to catch exceptions
>        ServletExceptionHandler handler = new ServletExceptionHandler();
>        handler.handle(pageContext,"/pages/error.jsf");
>    %>
>    </body>
> </html>
>
> best regards
> Keywan Ghadami
> -------- Original-Nachricht --------
>> Datum: Fri, 10 Jul 2009 09:43:24 +0200
>> Von: "liumin HU" <lhu@...>
>> An: "facelet list" <users@...>
>> Betreff: exeption in getter
>
>> hi everyone,
>>
>> Sometimes i have the nullpointer excption dans les getters. I think(not
>> sure) the facelet catches these exceptions and show a page with the detail of
>> the exception. I want to know if there is a way to handle this exception
>> by myself and redirect it to another page?
>>
>> thanks in adance
>>
>> liu
>
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: exeption in getter

by Liumin Hu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

@jan-kees van andel:

I am agree with you, we should avoid this kind of getter. but my case is a
little more complicate. I keep a key in the session For some reasons, this
key could be invalided by another application during the session and some
getter depens on this key. So i should raise some exception and redirect the
page to told the user the key has changed when this happened. this is my
problem.

@ keywan Ghadami

the filter does not work. the exception does not pass in filter.

liu
----- Original Message -----
From: "Jan-Kees van Andel" <jankeesvanandel@...>
To: <users@...>
Sent: Saturday, July 11, 2009 2:38 PM
Subject: Re: exeption in getter


Hey,

I prefer not to get Exceptions in getters. ;-) I think it is an
antipattern to put anything besides a return in a getter. Yeah, I know
about lazy loading tricks using if (var == null { /* initialize */ }
return var;, but my experience is that this leads to spaghetti code
where you don't know if and when some code is executed. I prefer just
putting logic in action methods. The only time this really doesn't
work is when you access pages directly and want to do some
post-processing, but there are other, more elegant, options for this
problem (frameworks for example).

When you only put logic in actions, you can implement a custom
ActionListener (see:
http://developers.sun.com/docs/jscreator/apis/jsf/javax/faces/event/ActionListener.html)
and registering it in your faces-config.xml (see:
http://stackoverflow.com/questions/464193/intercepting-exceptions-with-custom-jsf-event-handlers).

The advantage of using an ActionListener over a Filter is that you can
catch the exception inside the lifecycle. You can do some maintenance,
redirecting to an error page, displaying errors inline in your page
(using FacesContext.addMessage). Also, you don't have to turn off
Facelets and MyFaces development options.

Regards,
Jan-Kees



2009/7/10 Keywan Ghadami <Ghadami@...>:

> hi liu, in web.xhtml
> disable myfaces and faclet errorhandling by context parameters:
> <context-param>
> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
> <param-value>false</param-value>
> </context-param>
> <context-param>
> <param-name>facelets.DEVELOPMENT</param-name>
> <param-value>false</param-value>
> </context-param>
>
> I prefere to use a Filter to catch uncaught exceptions
> @Component //i use spring to automaticly setup my filters from classpath
> but u can ignore this Line and set u the filter in web.xml
>
>
> public class ExceptionFilterListener implements Filter{
>
> @Override
> public void destroy() {}
>
> @Override
> public void doFilter(ServletRequest servletRequest, ServletResponse
> servletResponse,
> FilterChain filterChain) throws IOException, ServletException {
> try {
> HttpServletRequest hr = (HttpServletRequest) servletRequest;
> String requestURI = hr.getRequestURI();
> filterChain.doFilter(servletRequest, servletResponse);
>
> } catch (Exception e) {
> HttpServletRequest hr = (HttpServletRequest) servletRequest;
> String requestURI = hr.getRequestURI();
> //The class handling the error and redirecting to my "nice error page"
> //sending some information to the administrator, browser,
> requestparameter, sessionparameter ...
> //This is done in a extra class, as there are many other places to catch
> exceptions
> ErrorHandler errorHandler = new ErrorHandler();
> errorHandler.handle(e,"/pages/error.xhtml",requestURI.toString(),
> servletResponse, servletRequest);
> }
> }
>
> @Override
> public void init(FilterConfig arg0) throws ServletException { }
>
> }
>
>
>
> But I also use a error page configured by web.xml
> <error-page>
> <exception-type>javax.servlet.ServletException</exception-type>
> <location>/pages/error.jsp</location>
> </error-page>
>
>
> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
> <%@page import="com.ibson.errorhandling.ServletExceptionHandler"%>
> <%@page isErrorPage="true" %>
> <html>
> <head></head>
> <body>
> <%
> //The class handling the error and redirecting to my "nice error page"
> //sending some information to the administrator, browser,
> requestparameter, sessionparameter ...
> //This is done in a extra class, as there are many other places to catch
> exceptions
> ServletExceptionHandler handler = new ServletExceptionHandler();
> handler.handle(pageContext,"/pages/error.jsf");
> %>
> </body>
> </html>
>
> best regards
> Keywan Ghadami
> -------- Original-Nachricht --------
>> Datum: Fri, 10 Jul 2009 09:43:24 +0200
>> Von: "liumin HU" <lhu@...>
>> An: "facelet list" <users@...>
>> Betreff: exeption in getter
>
>> hi everyone,
>>
>> Sometimes i have the nullpointer excption dans les getters. I think(not
>> sure) the facelet catches these exceptions and show a page with the
>> detail of
>> the exception. I want to know if there is a way to handle this exception
>> by myself and redirect it to another page?
>>
>> thanks in adance
>>
>> liu
>
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: exeption in getter

by ghadami :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,
I prefered a filter to catch all exception, e.g. they may occure on bean creation (@postconstruct).
you can setup the filter in web.xml, and the exception
will pass the filter if the filter is setup write - and if you disable Facelets and MyFaces development options.
 <filter>
  <display-name>ExceptionFilter</display-name>
  <filter-name>ExceptionFilter</filter-name>
  <filter-class>com.xy.exhandling.ExceptionFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>ExceptionFilter</filter-name>
  <servlet-name>Faces Servlet</servlet-name>
 </filter-mapping>

I agree with jan-kees van andel: Programming somthing in getters is the beginning from JSF-hell ^^.
If it's possible you can load the value (and throw exceptions) on bean creation in request scope. In spring i use "@postconstruct", (i don't know if myfaces supports this, without bugs, yet).
A getter would be called severel times in livecicle, so it is easer to have the same return value in a getter over some time.

regards
Keywan Ghadami


the filter does not work. the exception does not pass in filter.
liumin HU schrieb:

> hi,
>
> @jan-kees van andel:
>
> I am agree with you, we should avoid this kind of getter. but my case is a little more complicate. I keep a key in the session For some reasons, this key could be invalided by another application during the session and some getter depens on this key. So i should raise some exception and redirect the page to told the user the key has changed when this happened. this is my problem.
>
> @ keywan Ghadami
>
> the filter does not work. the exception does not pass in filter.
>
> liu
> ----- Original Message ----- From: "Jan-Kees van Andel" <jankeesvanandel@...>
> To: <users@...>
> Sent: Saturday, July 11, 2009 2:38 PM
> Subject: Re: exeption in getter
>
>
> Hey,
>
> I prefer not to get Exceptions in getters. ;-) I think it is an
> antipattern to put anything besides a return in a getter. Yeah, I know
> about lazy loading tricks using if (var == null { /* initialize */ }
> return var;, but my experience is that this leads to spaghetti code
> where you don't know if and when some code is executed. I prefer just
> putting logic in action methods. The only time this really doesn't
> work is when you access pages directly and want to do some
> post-processing, but there are other, more elegant, options for this
> problem (frameworks for example).
>
> When you only put logic in actions, you can implement a custom
> ActionListener (see:
> http://developers.sun.com/docs/jscreator/apis/jsf/javax/faces/event/ActionListener.html)
> and registering it in your faces-config.xml (see:
> http://stackoverflow.com/questions/464193/intercepting-exceptions-with-custom-jsf-event-handlers).
>
> The advantage of using an ActionListener over a Filter is that you can
> catch the exception inside the lifecycle. You can do some maintenance,
> redirecting to an error page, displaying errors inline in your page
> (using FacesContext.addMessage). Also, you don't have to turn off
> Facelets and MyFaces development options.
>
> Regards,
> Jan-Kees
>
>
>
> 2009/7/10 Keywan Ghadami <Ghadami@...>:
>> hi liu, in web.xhtml
>> disable myfaces and faclet errorhandling by context parameters:
>> <context-param>
>> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
>> <param-value>false</param-value>
>> </context-param>
>> <context-param>
>> <param-name>facelets.DEVELOPMENT</param-name>
>> <param-value>false</param-value>
>> </context-param>
>>
>> I prefere to use a Filter to catch uncaught exceptions
>> @Component //i use spring to automaticly setup my filters from classpath but u can ignore this Line and set u the filter in web.xml
>>
>>
>> public class ExceptionFilterListener implements Filter{
>>
>> @Override
>> public void destroy() {}
>>
>> @Override
>> public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
>> FilterChain filterChain) throws IOException, ServletException {
>> try {
>> HttpServletRequest hr = (HttpServletRequest) servletRequest;
>> String requestURI = hr.getRequestURI();
>> filterChain.doFilter(servletRequest, servletResponse);
>>
>> } catch (Exception e) {
>> HttpServletRequest hr = (HttpServletRequest) servletRequest;
>> String requestURI = hr.getRequestURI();
>> //The class handling the error and redirecting to my "nice error page"
>> //sending some information to the administrator, browser, requestparameter, sessionparameter ...
>> //This is done in a extra class, as there are many other places to catch exceptions
>> ErrorHandler errorHandler = new ErrorHandler();
>> errorHandler.handle(e,"/pages/error.xhtml",requestURI.toString(), servletResponse, servletRequest);
>> }
>> }
>>
>> @Override
>> public void init(FilterConfig arg0) throws ServletException { }
>>
>> }
>>
>>
>>
>> But I also use a error page configured by web.xml
>> <error-page>
>> <exception-type>javax.servlet.ServletException</exception-type>
>> <location>/pages/error.jsp</location>
>> </error-page>
>>
>>
>> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
>> <%@page import="com.ibson.errorhandling.ServletExceptionHandler"%>
>> <%@page isErrorPage="true" %>
>> <html>
>> <head></head>
>> <body>
>> <%
>> //The class handling the error and redirecting to my "nice error page"
>> //sending some information to the administrator, browser, requestparameter, sessionparameter ...
>> //This is done in a extra class, as there are many other places to catch exceptions
>> ServletExceptionHandler handler = new ServletExceptionHandler();
>> handler.handle(pageContext,"/pages/error.jsf");
>> %>
>> </body>
>> </html>
>>
>> best regards
>> Keywan Ghadami
>> -------- Original-Nachricht --------
>>> Datum: Fri, 10 Jul 2009 09:43:24 +0200
>>> Von: "liumin HU" <lhu@...>
>>> An: "facelet list" <users@...>
>>> Betreff: exeption in getter
>>
>>> hi everyone,
>>>
>>> Sometimes i have the nullpointer excption dans les getters. I think(not
>>> sure) the facelet catches these exceptions and show a page with the detail of
>>> the exception. I want to know if there is a way to handle this exception
>>> by myself and redirect it to another page?
>>>
>>> thanks in adance
>>>
>>> liu
>>
>> --
>> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
>> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


--
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: exeption in getter

by Liumin Hu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

thanks for your reply.

I have already a filter who catch all exception. Like what i said in last
mail, it cant catch the exception from getter. And I cant find a good way to
avoid this exception in getter for the moment.

after some research, i find a solution to catch this kind exception,  I
override handleRenderException of FaceletViewHandler. I dont know it is a
good way to do it.

best regards

liu

----- Original Message -----
From: "Keywan Ghadami" <Ghadami@...>
To: <users@...>
Sent: Saturday, July 18, 2009 12:11 AM
Subject: Re: exeption in getter


> hi,
> I prefered a filter to catch all exception, e.g. they may occure on bean
> creation (@postconstruct).
> you can setup the filter in web.xml, and the exception
> will pass the filter if the filter is setup write - and if you disable
> Facelets and MyFaces development options.
> <filter>
>  <display-name>ExceptionFilter</display-name>
>  <filter-name>ExceptionFilter</filter-name>
>  <filter-class>com.xy.exhandling.ExceptionFilter</filter-class>
> </filter>
> <filter-mapping>
>  <filter-name>ExceptionFilter</filter-name>
>  <servlet-name>Faces Servlet</servlet-name>
> </filter-mapping>
>
> I agree with jan-kees van andel: Programming somthing in getters is the
> beginning from JSF-hell ^^.
> If it's possible you can load the value (and throw exceptions) on bean
> creation in request scope. In spring i use "@postconstruct", (i don't know
> if myfaces supports this, without bugs, yet).
> A getter would be called severel times in livecicle, so it is easer to
> have the same return value in a getter over some time.
>
> regards
> Keywan Ghadami
>
>
> the filter does not work. the exception does not pass in filter.
> liumin HU schrieb:
>> hi,
>>
>> @jan-kees van andel:
>>
>> I am agree with you, we should avoid this kind of getter. but my case is
>> a little more complicate. I keep a key in the session For some reasons,
>> this key could be invalided by another application during the session and
>> some getter depens on this key. So i should raise some exception and
>> redirect the page to told the user the key has changed when this
>> happened. this is my problem.
>>
>> @ keywan Ghadami
>>
>> the filter does not work. the exception does not pass in filter.
>>
>> liu
>> ----- Original Message ----- From: "Jan-Kees van Andel"
>> <jankeesvanandel@...>
>> To: <users@...>
>> Sent: Saturday, July 11, 2009 2:38 PM
>> Subject: Re: exeption in getter
>>
>>
>> Hey,
>>
>> I prefer not to get Exceptions in getters. ;-) I think it is an
>> antipattern to put anything besides a return in a getter. Yeah, I know
>> about lazy loading tricks using if (var == null { /* initialize */ }
>> return var;, but my experience is that this leads to spaghetti code
>> where you don't know if and when some code is executed. I prefer just
>> putting logic in action methods. The only time this really doesn't
>> work is when you access pages directly and want to do some
>> post-processing, but there are other, more elegant, options for this
>> problem (frameworks for example).
>>
>> When you only put logic in actions, you can implement a custom
>> ActionListener (see:
>> http://developers.sun.com/docs/jscreator/apis/jsf/javax/faces/event/ActionListener.html)
>> and registering it in your faces-config.xml (see:
>> http://stackoverflow.com/questions/464193/intercepting-exceptions-with-custom-jsf-event-handlers).
>>
>> The advantage of using an ActionListener over a Filter is that you can
>> catch the exception inside the lifecycle. You can do some maintenance,
>> redirecting to an error page, displaying errors inline in your page
>> (using FacesContext.addMessage). Also, you don't have to turn off
>> Facelets and MyFaces development options.
>>
>> Regards,
>> Jan-Kees
>>
>>
>>
>> 2009/7/10 Keywan Ghadami <Ghadami@...>:
>>> hi liu, in web.xhtml
>>> disable myfaces and faclet errorhandling by context parameters:
>>> <context-param>
>>> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
>>> <param-value>false</param-value>
>>> </context-param>
>>> <context-param>
>>> <param-name>facelets.DEVELOPMENT</param-name>
>>> <param-value>false</param-value>
>>> </context-param>
>>>
>>> I prefere to use a Filter to catch uncaught exceptions
>>> @Component //i use spring to automaticly setup my filters from classpath
>>> but u can ignore this Line and set u the filter in web.xml
>>>
>>>
>>> public class ExceptionFilterListener implements Filter{
>>>
>>> @Override
>>> public void destroy() {}
>>>
>>> @Override
>>> public void doFilter(ServletRequest servletRequest, ServletResponse
>>> servletResponse,
>>> FilterChain filterChain) throws IOException, ServletException {
>>> try {
>>> HttpServletRequest hr = (HttpServletRequest) servletRequest;
>>> String requestURI = hr.getRequestURI();
>>> filterChain.doFilter(servletRequest, servletResponse);
>>>
>>> } catch (Exception e) {
>>> HttpServletRequest hr = (HttpServletRequest) servletRequest;
>>> String requestURI = hr.getRequestURI();
>>> //The class handling the error and redirecting to my "nice error page"
>>> //sending some information to the administrator, browser,
>>> requestparameter, sessionparameter ...
>>> //This is done in a extra class, as there are many other places to catch
>>> exceptions
>>> ErrorHandler errorHandler = new ErrorHandler();
>>> errorHandler.handle(e,"/pages/error.xhtml",requestURI.toString(),
>>> servletResponse, servletRequest);
>>> }
>>> }
>>>
>>> @Override
>>> public void init(FilterConfig arg0) throws ServletException { }
>>>
>>> }
>>>
>>>
>>>
>>> But I also use a error page configured by web.xml
>>> <error-page>
>>> <exception-type>javax.servlet.ServletException</exception-type>
>>> <location>/pages/error.jsp</location>
>>> </error-page>
>>>
>>>
>>> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
>>> <%@page import="com.ibson.errorhandling.ServletExceptionHandler"%>
>>> <%@page isErrorPage="true" %>
>>> <html>
>>> <head></head>
>>> <body>
>>> <%
>>> //The class handling the error and redirecting to my "nice error page"
>>> //sending some information to the administrator, browser,
>>> requestparameter, sessionparameter ...
>>> //This is done in a extra class, as there are many other places to catch
>>> exceptions
>>> ServletExceptionHandler handler = new ServletExceptionHandler();
>>> handler.handle(pageContext,"/pages/error.jsf");
>>> %>
>>> </body>
>>> </html>
>>>
>>> best regards
>>> Keywan Ghadami
>>> -------- Original-Nachricht --------
>>>> Datum: Fri, 10 Jul 2009 09:43:24 +0200
>>>> Von: "liumin HU" <lhu@...>
>>>> An: "facelet list" <users@...>
>>>> Betreff: exeption in getter
>>>
>>>> hi everyone,
>>>>
>>>> Sometimes i have the nullpointer excption dans les getters. I think(not
>>>> sure) the facelet catches these exceptions and show a page with the
>>>> detail of
>>>> the exception. I want to know if there is a way to handle this
>>>> exception
>>>> by myself and redirect it to another page?
>>>>
>>>> thanks in adance
>>>>
>>>> liu
>>>
>>> --
>>> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
>>> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@...
>>> For additional commands, e-mail: users-help@...
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>
>
> --
> Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
> für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...