myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gcrawf...@apache.org
Subject svn commit: r639757 - in /myfaces/trinidad/trunk: trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/ trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/
Date Fri, 21 Mar 2008 18:55:59 GMT
Author: gcrawford
Date: Fri Mar 21 11:55:55 2008
New Revision: 639757

URL: http://svn.apache.org/viewvc?rev=639757&view=rev
Log:
TRINIDAD-1023 filedownloadActionListener does not tell user when there are errors

Catch exceptions, reset the response, add an error message to the faces context and call renderResponse.


Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts?rev=639757&r1=639756&r2=639757&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
Fri Mar 21 11:55:55 2008
@@ -442,5 +442,9 @@
   <!-- {1} = full formatted error message detail                       -->
   <resource key="org.apache.myfaces.trinidad.convert.ALERT_FORMAT">{0} - {1}</resource>
   <resource key="org.apache.myfaces.trinidad.convert.ALERT_FORMAT_detail">{0} - {1}</resource>
+  
+  <!-- message for error while downloading a file  -->
+  <resource key="org.apache.myfaces.trinidad.event.FileDownloadActionListener.DOWNLOAD_ERROR">Download
Error</resource>
+  <resource key="org.apache.myfaces.trinidad.event.FileDownloadActionListener.DOWNLOAD_ERROR_detail">An
error was encountered while downloading.</resource>  
 
 </resources>

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx?rev=639757&r1=639756&r2=639757&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
(original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
Fri Mar 21 11:55:55 2008
@@ -34,6 +34,7 @@
             <tr:goLink destination="http://myfaces.apache.org/trinidad/trinidad-api/tagdoc/tr_fileDownloadActionListener.html"
                        text="Tag Documentation"/>
           </tr:panelGroupLayout>
+          <tr:messages/>
           <tr:outputFormatted styleUsage="instruction"
                               value="&lt;b>fileDownloadActionListener&lt;/b>"/>
           <tr:outputText value="Click any command component to download a file"/>

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java?rev=639757&r1=639756&r2=639757&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java
Fri Mar 21 11:55:55 2008
@@ -19,9 +19,9 @@
 package org.apache.myfaces.trinidadinternal.taglib.listener;
 
 import java.io.BufferedOutputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 
+import javax.faces.application.FacesMessage;
 import javax.faces.component.StateHolder;
 import javax.faces.context.FacesContext;
 import javax.faces.el.MethodBinding;
@@ -36,6 +36,8 @@
 import org.apache.myfaces.trinidad.bean.PropertyKey;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.util.ComponentUtils;
+import org.apache.myfaces.trinidad.util.MessageFactory;
+
 
 /**
  * @todo Look at moving to org.apache.myfaces.trinidad.event
@@ -58,6 +60,14 @@
                      MethodBinding.class,
                      PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_STATE_HOLDER);
 
+
+  /**
+    * <p>The message identifier of the {@link FacesMessage} to be created when
+    * there is a download error.</p>
+    */
+     public static final String DOWNLOAD_MESSAGE_ID =
+         "org.apache.myfaces.trinidad.event.FileDownloadActionListener.DOWNLOAD_ERROR"; 

+
   static
   {
     TYPE.lock();
@@ -80,9 +90,9 @@
     }
     else
     {
+      HttpServletResponse hsr = (HttpServletResponse) response;
       try
       {
-        HttpServletResponse hsr = (HttpServletResponse) response;
         if (contentType != null)
           // TODO: encoding?
           hsr.setContentType(contentType);
@@ -92,19 +102,18 @@
                         "attachment; filename=" + filename);
         MethodBinding method = getMethod();
         OutputStream out = new BufferedOutputStream(hsr.getOutputStream());
-        try
-        {
           method.invoke(context, new Object[]{context, out});
-        }
-        finally
-        {
           out.close();
-        }
          
       }
-      catch (IOException ioe)
+      catch (Exception e)
       {
-        _LOG.warning(ioe);
+        hsr.reset();
+        _LOG.warning(e);       
+        FacesMessage message = MessageFactory.getMessage(context, DOWNLOAD_MESSAGE_ID);
+        context.addMessage(null, message);
+        context.renderResponse();
+        return;
       }
     }
     



Mime
View raw message