@Thiago - I am using Tapestry 5.1.0.5.

@Martin - here is my code.  This code works when called from onActivate()
and returns the file.

JAVA

@Log 
StreamResponse onSuccess() { 

try { 

    File tmpFile = File.createTempFile(urlFile.getFileName(), null); 
    BufferedWriter br = new BufferedWriter(new FileWriter(tmpFile)); 
    br.append("something to test\nAnother line to test"); 
    br.flush(); 
    br.close(); 

    return new CsvStreamResponse(new
FileInputStream(tmpFile.getAbsolutePath()), "results_file"); 
 } catch (IOException e) { 
     e.printStackTrace(); 
     addError("An Error occured while streaming back the results."); 
 } 

   return null; 
} 

public class CsvStreamResponse implements StreamResponse { 
    private InputStream is; 
    private String filename; 

    public CsvStreamResponse(InputStream is, String filename) { 
            this.is = is; 
            this.filename = filename; 
    } 

    public String getContentType() { 
            return "text/csv"; 
    } 

    public InputStream getStream() throws IOException { 
            return is; 
    } 

    public void prepareResponse(Response arg0) { 
            arg0.setHeader("Content-Disposition", "attachment; filename=" +
filename + ".csv"); 
            //also tried setting content length after this -
arg0.setContentLength(is.available());
    } 
} 



TML
<form t:type="form" t:id="analysis">
    <t:upload t:id="urlFile" class="marginRight" validate="required"/>
    <t:submit class="marginRight white button medium"
value="${message:button.upload}" t:id="upload"/>
</form>




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/redirect-after-post-messes-with-my-StreamResponse-tp4763647p4764159.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to