myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gcrawf...@apache.org
Subject svn commit: r639754 - in /myfaces/trinidad/trunk_1.2.x: 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/...
Date Fri, 21 Mar 2008 18:40:40 GMT
Author: gcrawford
Date: Fri Mar 21 11:40:38 2008
New Revision: 639754

URL: http://svn.apache.org/viewvc?rev=639754&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_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
    myfaces/trinidad/trunk_1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
    myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts?rev=639754&r1=639753&r2=639754&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
Fri Mar 21 11:40:38 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_1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx?rev=639754&r1=639753&r2=639754&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/fileDownloadActionListener.jspx
Fri Mar 21 11:40:38 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_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java?rev=639754&r1=639753&r2=639754&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/listener/FileDownloadActionListener.java
Fri Mar 21 11:40:38 2008
@@ -19,12 +19,11 @@
 package org.apache.myfaces.trinidadinternal.taglib.listener;
 
 import java.io.BufferedOutputStream;
-import java.io.IOException;
 import java.io.OutputStream;
 
 import javax.el.MethodExpression;
-import javax.el.ValueExpression;
 
+import javax.faces.application.FacesMessage;
 import javax.faces.component.StateHolder;
 import javax.faces.context.FacesContext;
 import javax.faces.event.ActionEvent;
@@ -37,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 +59,14 @@
     TYPE.registerKey("method",
                      MethodExpression.class,
                      PropertyKey.CAP_NOT_BOUND);
+  
+
+  /**
+    * <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
   {
@@ -81,9 +90,9 @@
     }
     else
     {
+      HttpServletResponse hsr = (HttpServletResponse) response;
       try
       {
-        HttpServletResponse hsr = (HttpServletResponse) response;
         if (contentType != null)
           // TODO: encoding?
           hsr.setContentType(contentType);
@@ -91,21 +100,21 @@
           // TODO: what about non-ASCII characters in the filename?
           hsr.setHeader("Content-Disposition",
                         "attachment; filename=" + filename);
+        
         MethodExpression method = getMethod();
         OutputStream out = new BufferedOutputStream(hsr.getOutputStream());
-        try
-        {
-          method.invoke(context.getELContext(), new Object[]{context, out});
-        }
-        finally
-        {
-          out.close();
-        }
+        method.invoke(context.getELContext(), new Object[]{context, out});
+        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