you're welcome

Notice that there is no need to explicitly inject the request and response into your service since they both get autowired by hivemind's magic :) if you provide setters for them, which mean that you can also inject any other service you need (like a hibernate service or a excel generator or pdf generator etc...)


Inge Solvoll wrote:
Excellent info, Raul!! Thanks a lot.

On 1/26/06, Raul Raja Martinez <[EMAIL PROTECTED]> wrote:
Yes it is possible, ussing a implementation of IEngineService such as:

public class ExcelToBrowser implements IEngineService {

  private void toBrowser(HttpServletRequest request,
HttpServletResponse
response) {
   try {

        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate,
post-check=0,
pre-check=0");
        response.setHeader("Pragma", "public");
        // setting the content type
        response.setContentType("application/octect-stream");
        // the contentlength is needed for MSIE!!!

        ServletOutputStream out = response.getOutputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        //Here your excel generation library might have some way to put
the
stream to baos

        baos.writeTo(out);
        out.flush();



    } catch (Exception e2) {
        //Exception handling
    }





        public String getName() {
                return "excelToBrowser";
        }

        private HttpServletResponse response;

        public void setResponse (HttpServletResponse response) {
                this.response = response;
        }

        private HttpServletRequest request;

        public void setRequest (HttpServletRequest request) {
                this.request = request;
        }


        public void service(IRequestCycle arg0) throws IOException {

                        makeTXT(request, response);

        }

        public ILink getLink(boolean arg0, Object arg1) {
                return null;
        }
}


Later in your hivemodule.xml:

<contribution configuration-id="tapestry.services.ApplicationServices">
  <service name="pdf" object="service:ExcelToBrowser" />
</contribution>

<service-point id="ExcelBrowser"
interface="org.apache.tapestry.engine.IEngineService">
  <invoke-factory model="singleton">
   <construct class="yourpackage.ExcelToBrowser" />
  </invoke-factory>
</service-point>

Even though this example doesn't directly show how to output the excel
file you might find it useful to output pretty much any kind of file,
what your browser will use to handle the file is
response.setContentType("application/octect-stream"); refer to other
mime types at: http://www.iana.org/assignments/media-types/ to tell your
browser how to handle other extension
you can create links to your service using the Service Link:

http://jakarta.apache.org/tapestry/tapestry/ComponentReference/ServiceLink.html

best regards.

Raul Raja.


Vincent wrote:
I would like to popup excel file into the client web browser, then he
can decide whether to open it , or save to the disk,  is it possible
to do that in Tapestry?

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





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

Reply via email to