You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Vincent <vi...@gmail.com> on 2006/01/26 09:32:49 UTC

How to popup excel file in the IE?

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?

Re: How to popup excel file in the IE?

Posted by Vincent <vi...@gmail.com>.
Thanks guys, I got it and also works well :-)

On 1/27/06, Raul Raja Martinez <do...@estudiowebs.com> wrote:
> In Tapestry 4 when you create an Engine Service you have to tell your
> hivemodule.xml that it exists so that Hivemind injects the service when
> needed.
> You might want to look at an introduction of IoC
> http://www.martinfowler.com/articles/injection.html
>
> Hivemind is kind of a inversion of control container, you declare
> services into it and the you can later inject them anywhere in your
> application. for example you could create a :
> Database access service with a singleton pattern and the when needed you
> could just inject it into one of your components or pages without the
> need of having to instantiate it.
>
> It is way easier than it looks and its way powerful.
>
> best regards.
>
> Raul.
>
>
> Vincent wrote:
> >>> 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>
> > Hi guys,
> >
> > Thank you for you information , I am new to Tapestry , what does this
> > needs to use
> > hivemodule.xml?
> >
> > regards,
> > Vincent
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: How to popup excel file in the IE?

Posted by Raul Raja Martinez <do...@estudiowebs.com>.
In Tapestry 4 when you create an Engine Service you have to tell your
hivemodule.xml that it exists so that Hivemind injects the service when 
needed.
You might want to look at an introduction of IoC 
http://www.martinfowler.com/articles/injection.html

Hivemind is kind of a inversion of control container, you declare 
services into it and the you can later inject them anywhere in your 
application. for example you could create a :
Database access service with a singleton pattern and the when needed you 
could just inject it into one of your components or pages without the 
need of having to instantiate it.

It is way easier than it looks and its way powerful.

best regards.

Raul.


Vincent wrote:
>>> 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>
> Hi guys,
> 
> Thank you for you information , I am new to Tapestry , what does this
> needs to use
> hivemodule.xml?
> 
> regards,
> Vincent


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to popup excel file in the IE?

Posted by Vincent <vi...@gmail.com>.
> > 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>
Hi guys,

Thank you for you information , I am new to Tapestry , what does this
needs to use
hivemodule.xml?

regards,
Vincent

Re: How to popup excel file in the IE?

Posted by Geoff Longman <gl...@gmail.com>.
BTW if you want the browser to show an "Open/Save" dialog you need to
set the Content-Disposition header too.

Geoff

On 1/26/06, Raul Raja Martinez <do...@estudiowebs.com> 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: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


--
The Spindle guy.          http://spindle.sf.net
Get help with Spindle:   
http://lists.sourceforge.net/mailman/listinfo/spindle-user
Blog:                     http://jroller.com/page/glongman
Feature Updates:          http://spindle.sf.net/updates

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to popup excel file in the IE?

Posted by Raul Raja Martinez <do...@estudiowebs.com>.
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 <do...@estudiowebs.com> 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: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to popup excel file in the IE?

Posted by Inge Solvoll <in...@gmail.com>.
Excellent info, Raul!! Thanks a lot.

On 1/26/06, Raul Raja Martinez <do...@estudiowebs.com> 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: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: How to popup excel file in the IE?

Posted by Raul Raja Martinez <do...@estudiowebs.com>.
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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org