Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The following page has been changed by DanielJue:
http://wiki.apache.org/tapestry/Tapestry5HowToCreateADynamicPDF

The comment on the change is:
Added a simple intro to Varargs, ability to set the response header and filename

------------------------------------------------------------------------------
  
  public class PDFStreamResponse implements StreamResponse {
        private InputStream is;
-       private String filename;
+       private String filename="default";
  
-       public PDFStreamResponse(InputStream is, String filename) {
+       public PDFStreamResponse(InputStream is, String... args) {
                this.is = is;
-               this.filename = filename;
- 
+               if (args != null) {
+                       this.filename = args[0];
+               }
        }
  
        public String getContentType() {
@@ -154, +155 @@

  
  }}}
  
+ Note that the constructor above uses feature new to Java 1.5, the varargs 
feature.  
+ It is included here simply as an introduction to it.  
+ 
+ What it does in this case is allow you to create a PDFStreamResponse with or 
without supplying a filename.
+ To do this in Java 1.4, we'd have to create a separate constructor that did 
not have a parameter for the filename.
+ 
+ So now, you can do this:
+ {{{
+ ...
+ return new PDFStreamResponse(is, "DynamicSample");
+ ...
+ }}}
+ (The filename will be DynamicSample.pdf)
+ or this:
+ 
+ {{{
+ ...
+ return new PDFStreamResponse(is);
+ ...
+ }}}
+ (the filename will be default.pdf)
+ 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to