2 Replies Latest reply on Oct 2, 2010 4:36 PM by he youlin

    Can't deactivateConversations when exception occurred in jsf

    he youlin Novice

      In latest weld core deactivateConversations is after RENDERRESPONSE and RENDERRESPONSE.
      When before RENDERRESPONSE any phase occur exception jsf will handle this exception and complete response after AfterPhase and skip RENDERRESPONSE. So weld can not deactivateConversations.

        • 2. Re: Can't deactivateConversations when exception occurred in jsf
          he youlin Novice
          I created a jira to jsf2 
          [=>https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1812]
          
          I create a ExceptionHandler to handle this exception instead of jsf2 default handle like this in seam2.0
          
          I don't konow if this is a seam bug or jsf bug.
          
          public class DelegatingExceptionHandler extends ExceptionHandlerWrapper
          {
          
          .......
          
          @Override
             public void handle() throws FacesException
             {
                ExceptionQueuedEvent handled = null;
                Iterator<ExceptionQueuedEvent> exs = getUnhandledExceptionQueuedEvents().iterator();
                if(exs.hasNext())
                {
                   handled=exs.next();
                   ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) handled.getSource();
                   FacesContext facesContext=context.getContext();
                   ExternalContext externalContext = facesContext.getExternalContext();
                   
                   try
                   {
                      if (facesContext.getPartialViewContext().isAjaxRequest()) 
                      { 
                        externalContext.setResponseContentType("text/xml");
                        externalContext.addResponseHeader("Cache-Control", "no-cache");
                        PartialResponseWriter writer =
                          facesContext.getPartialViewContext().getPartialResponseWriter();
                        
                        writer.startDocument();
                        writer.startUpdate("javax.faces.ViewRoot");
                        writer.startElement("span",null);
                        writer.writeAttribute("id","target","id");
                        writer.endElement("span");
                        writer.startElement("script",null);
                        writer.writeAttribute("type","text/javascript","type");
                        writer.write("alert('"+context.getException().getMessage()+"');");
                        writer.endElement("script");
                        writer.endUpdate();
                        writer.endDocument();
                        writer.flush();
                        facesContext.responseComplete();
                        Manager.instance().endRequest( externalContext.getSessionMap() );
                        FacesLifecycle.endRequest( externalContext );    
                     }
                     else
                     {
                       Exceptions.instance().handle(new Exception(context.getException()));
                     }
                      exs.remove();
                   }
                   catch (Exception e)
                   {
                      getWrapped().handle();
                      if(facesContext.getRenderResponse() || facesContext.getResponseComplete())
                      {
                         externalContext = facesContext.getExternalContext();
                         Manager.instance().endRequest( externalContext.getSessionMap() );
                         FacesLifecycle.endRequest( externalContext );
                      }   
                   }
                        
                }
                
             }
          
          ...........
          
          }