Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added StreamResponse example, with thanks to xl0e (http://stackoverflow.com/questions/42840783/download-display-file-stored-in-sql-table)

...

The URL for a component event request identifies the name of the page, the nested id of the component, and the name of the event to trigger on the component (this is usually specified by the "event" parameter of EventLink, or "action" for an ActionLink). Further, a component event request may contain additional context information, which will be provided to the event handler method.

...

An event handler can also return a StreamResponse object, which encapsulates a stream to be sent directly to the client browser. This is useful for components that want to, say, generate an image or PDF and provide it to the client:

Code Block
public Object onAction(){
    return new StreamResponse() {
        @Override
        public String getContentType() {
            return "application/pdf";
        }
        @Override
        public InputStream getStream() throws IOException {
            return new ByteArrayInputStream(getMyPdfByteArray());
        }
        @Override
        public void prepareResponse(Response response) {
            response.setHeader("Content-Disposition", "attachment; filename=\"" + myFileName + "\"");
        }
    };
}

 

A java.net.URL response is handled as a client redirect to an external URL. (In Tapestry 5.3.x and earlier this only works for non-Ajax requests.)

...