Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Catch Exceptions In JSF Page (View) : Problems

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have two Classes that extend from ExceptionHandlerWrapper & ExceptionHandlerFactory for catching any exceptions that occur in the view layer and navigate to error page and show this error. So I need store or save this exceptions somewhere but I can`t get this exception message. I tried to get this message in session but I need another way to save this message with out ViewScope and PageFlowScope and RequestScope.


public class CustomExceptionHandlerFactory extends ExceptionHandlerFactory {

   private ExceptionHandlerFactory parent;
   
   public CustomExceptionHandlerFactory(ExceptionHandlerFactory parent) {
     this.parent = parent;
   }
   
   @Override
   public ExceptionHandler getExceptionHandler() {
     ExceptionHandler result = new CustomExceptionHandler(parent.getExceptionHandler());
     return result;
   }
}


public class CustomExceptionHandler extends ExceptionHandlerWrapper {
   private ExceptionHandler wrapped;


   public CustomExceptionHandler(ExceptionHandler wrapped) {
       this.wrapped = wrapped;
   }

   @Override
   public ExceptionHandler getWrapped() {
       return wrapped;
   }

   @Override
   public void handle() throws FacesException {
       Iterator iterator = getUnhandledExceptionQueuedEvents().iterator();

       while (iterator.hasNext()) {
           ExceptionQueuedEvent event = (ExceptionQueuedEvent) iterator.next();
           ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();


           Throwable throwable = context.getException();
           FacesContext fc = FacesContext.getCurrentInstance();


            Map<String, Object> sessionMap = fc.getExternalContext().getSessionMap();
            NavigationHandler navigator = fc.getApplication().getNavigationHandler();
           
           
           AdfFacesContext adfc = AdfFacesContext.getCurrentInstance();
           
        // Map<String,Object> valueViewScope =   adfc.getViewScope();
           

           try {
               //  Flash flash = fc.getExternalContext().getFlash();
               // Put the exception in the flash scope to be displayed in the error
               // page if necessary ...
               //  flash.put("errorDetails", throwable.getMessage());

              // ADFContext.getCurrent().getSessionScope().put("errorDetails", throwable.getMessage());

               sessionMap.put("errorDetails", throwable.getMessage());

               System.out.println("the error is put in the Session: " + throwable.getMessage());

               //NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
               navigator.handleNavigation(fc, null, "ErrorPage?faces-redirect=true");
               // navigationHandler.handleNavigation(fc, null, "ErrorPage?faces-redirect=true");

               fc.renderResponse();
           } finally {
             
           }
       }

       // Let the parent handle the rest
       getWrapped().handle();
   }
}





Please I need Another Way To Store - or Save This Value
In SessionScope But i Need Another Way
WithOut Any Value In Session Beacuse Will Get Null in Bean
But In Page Error Showd successfully
because value in session  
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic