You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Raj Saini <ra...@gmail.com> on 2006/04/08 17:06:06 UTC

Force downloading a file in JSF portlet

Hi,


I am building JSF based portlet for downloading a file using MyFaces JSF 
bridge.
I do the following to make the file force download:

1) Set "content-disposition" header to contain the correct filename
2) Set "content-type" header to "application/octet-stream" or something
more accurate if the information is present in attachment metadata
3) Dump the content using a ServletOutputStream

When I click on the link to download the file, instead of throwing a 
dialog box for saving/opening the file, browser dumps the the binary 
contents on page. However, this works fine as standalone application.

Is there something extra I need to do to force download file in 
Jetspeed? Am I missing something here?

Regards,

Raj




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


Re: Force downloading a file in JSF portlet

Posted by Aaron Evans <aa...@gmail.com>.
I don't think you may do request forwarding from a portlet application
(but you can do redirects and includes).

So, instead of creating the download link via  a "command link" that
maps to an action listener that will handle the download, you use a
link that points to a servlet that will take the place of the action
listener for the download.  I know, it's not pretty, but it will work
and it's portable.

As Vlad has explained, you can simply output a link in your portlet's
rendered markup that is the URI to a servlet that is also a part of
your servlet/portlet web app.

So, to mimic Vlad's example, you put something like this in your
web.xml (where com.mycompany.servlet.MyDownloadServlet is the servlet
that will write the content to the output stream):

<web-app>
...
 <servlet>
   <servlet-name>documents</servlet-name>
   <servlet-class>com.mycompany.servlet.MyDownloadServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>
...


 <servlet-mapping>
   <servlet-name>documents</servlet-name>
   <url-pattern>/documents/download.do</url-pattern>
 </servlet-mapping>
...
</web-app>

Then, if you output a link to /<web app
context>/documents/download.do, when a user clicks it, then the
content will be served by that servlet and you can then alter the
response headers and write binary content to the output stream from
within the servlet code.

The way you generate the actual link is irrelevant, you can use a JSF
tag (which I am not too familiar with), or you can simply write the
string directly (ie <%= myURIString  %>).

HTH,
aaron

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


Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Hi Aaron,


Can you tell me in little more details, how to give link to a servlet
in JSF? Currently I am using CommandLink component and I dont see a
way of giving direct link to servlet.

Regards,

Raj


On 4/9/06, Aaron Evans <aa...@gmail.com> wrote:
> Raj,
>
> A portlet cannot alter those response headers the way a servlet can.
>
> I believe your options are to either use the file server component of
> the pipeline (which to be honest I don't know much about) or you could
> simply make the link a link to a servlet within your application,
> thereby by-passing jetspeed.
>
> HTH,
> aaron
>
> On 4/8/06, Raj Saini <ra...@gmail.com> wrote:
> > Hi,
> >
> >
> > I am building JSF based portlet for downloading a file using MyFaces JSF
> > bridge.
> > I do the following to make the file force download:
> >
> > 1) Set "content-disposition" header to contain the correct filename
> > 2) Set "content-type" header to "application/octet-stream" or something
> > more accurate if the information is present in attachment metadata
> > 3) Dump the content using a ServletOutputStream
> >
> > When I click on the link to download the file, instead of throwing a
> > dialog box for saving/opening the file, browser dumps the the binary
> > contents on page. However, this works fine as standalone application.
> >
> > Is there something extra I need to do to force download file in
> > Jetspeed? Am I missing something here?
> >
> > Regards,
> >
> > Raj
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> > For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

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


Re: Force downloading a file in JSF portlet

Posted by Aaron Evans <aa...@gmail.com>.
Raj,

A portlet cannot alter those response headers the way a servlet can.

I believe your options are to either use the file server component of
the pipeline (which to be honest I don't know much about) or you could
simply make the link a link to a servlet within your application,
thereby by-passing jetspeed.

HTH,
aaron

On 4/8/06, Raj Saini <ra...@gmail.com> wrote:
> Hi,
>
>
> I am building JSF based portlet for downloading a file using MyFaces JSF
> bridge.
> I do the following to make the file force download:
>
> 1) Set "content-disposition" header to contain the correct filename
> 2) Set "content-type" header to "application/octet-stream" or something
> more accurate if the information is present in attachment metadata
> 3) Dump the content using a ServletOutputStream
>
> When I click on the link to download the file, instead of throwing a
> dialog box for saving/opening the file, browser dumps the the binary
> contents on page. However, this works fine as standalone application.
>
> Is there something extra I need to do to force download file in
> Jetspeed? Am I missing something here?
>
> Regards,
>
> Raj
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

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


Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Thanks, Vlad, Aron. It is working fine now.

Regards,

Raj

Vladimir Figurov wrote:

> I don't use a CommandLink
> I use a outputLink :
>
> <h:outputLink 
> value="#{facesContext.externalContext.requestContextPath}/documents/#{dataRow['name4url']}/?doc_id=#{dataRow['docId']}" 
> target="_blank" >
>                    <h:outputText value="It's link"/>
>                </h:outputLink>
>
>
> How can you see, I use "*/documents/*" key in href....
> This url-part a listing a my Doc_view servlet.
>
>
>
> Raj Saini wrote:
>
>> Vladimir,
>>
>> Thanks for you help till now. I feel I am still missing something. I
>> am not able to forward the control from my JSF page to servlet. My
>> servlet is configured fine and it is working standalone.
>>
>> I searched the web for help on how to forward request to a servlet
>> from JSF page and based on it I call an action method in my JSF page
>> and action method returns a String.
>>
>> <code>
>> public String download() {
>>        System.out.println("Inside download method");
>>        return "/knowledge-base/download";
>>    }
>> </code>
>>
>> However, request is never forwarded to servlet. Can you throw some
>> light? Can you tell me how do you forward request from JSF page to
>> servlet? What do you specify in the action attribute of your
>> CommandLink component?
>>
>> Thanks,
>>
>> Raj
>>
>> On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
>>  
>>
>>> 8-O
>>>
>>> It's simple - need add to web.xml next elements:
>>>
>>> <web-app>
>>> ...
>>>  <servlet>
>>>    <servlet-name>documents</servlet-name>
>>>    <servlet-class>asoft.web.Doc_view</servlet-class>
>>>    <load-on-startup>1</load-on-startup>
>>>  </servlet>
>>> ...
>>>
>>>
>>>  <servlet-mapping>
>>>    <servlet-name>documents</servlet-name>
>>>    <url-pattern>/documents/*</url-pattern>
>>>  </servlet-mapping>
>>> ...
>>> </web-app>
>>>
>>>
>>>   
>>
>
>


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


Re: Force downloading a file in JSF portlet

Posted by Vladimir Figurov <VF...@asia-soft.kz>.
I don't use a CommandLink
I use a outputLink :

<h:outputLink 
value="#{facesContext.externalContext.requestContextPath}/documents/#{dataRow['name4url']}/?doc_id=#{dataRow['docId']}" 
target="_blank" >
                    <h:outputText value="It's link"/>
                </h:outputLink>


How can you see, I use "*/documents/*" key in href....
This url-part a listing a my Doc_view servlet.



Raj Saini wrote:

>Vladimir,
>
>Thanks for you help till now. I feel I am still missing something. I
>am not able to forward the control from my JSF page to servlet. My
>servlet is configured fine and it is working standalone.
>
>I searched the web for help on how to forward request to a servlet
>from JSF page and based on it I call an action method in my JSF page
>and action method returns a String.
>
><code>
> public String download() {
>    	System.out.println("Inside download method");
>    	return "/knowledge-base/download";
>    }
></code>
>
>However, request is never forwarded to servlet. Can you throw some
>light? Can you tell me how do you forward request from JSF page to
>servlet? What do you specify in the action attribute of your
>CommandLink component?
>
>Thanks,
>
>Raj
>
>On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
>  
>
>>8-O
>>
>>It's simple - need add to web.xml next elements:
>>
>><web-app>
>>...
>>  <servlet>
>>    <servlet-name>documents</servlet-name>
>>    <servlet-class>asoft.web.Doc_view</servlet-class>
>>    <load-on-startup>1</load-on-startup>
>>  </servlet>
>>...
>>
>>
>>  <servlet-mapping>
>>    <servlet-name>documents</servlet-name>
>>    <url-pattern>/documents/*</url-pattern>
>>  </servlet-mapping>
>>...
>></web-app>
>>
>>
>>    
>>


-- 
Vladimir


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


Re: Force downloading a file in JSF portlet

Posted by Ge <ge...@gmail.com>.
Hi,

I've 2 alternately suggestion:
1. Write the code in a jsp file instead of the servlet.
2. in the faces-config.xml file, config the action to an jsp file,
 write code forward the request to your servlet in the jsp file.

Hope be helpful.

David

-----Original Message-----
From: Raj Saini [mailto:rajsaini@gmail.com]
Sent: Monday, April 10, 2006 7:28 PM
To: Jetspeed Users List
Subject: Re: Force downloading a file in JSF portlet

Vladimir,

Thanks for you help till now. I feel I am still missing something. I
am not able to forward the control from my JSF page to servlet. My
servlet is configured fine and it is working standalone.

I searched the web for help on how to forward request to a servlet
from JSF page and based on it I call an action method in my JSF page
and action method returns a String.

<code>
 public String download() {
    	System.out.println("Inside download method");
    	return "/knowledge-base/download";
    }
</code>

However, request is never forwarded to servlet. Can you throw some
light? Can you tell me how do you forward request from JSF page to
servlet? What do you specify in the action attribute of your
CommandLink component?

Thanks,

Raj

On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> 8-O
>
> It's simple - need add to web.xml next elements:
>
> <web-app>
> ...
>   <servlet>
>     <servlet-name>documents</servlet-name>
>     <servlet-class>asoft.web.Doc_view</servlet-class>
>     <load-on-startup>1</load-on-startup>
>   </servlet>
> ...
>
>
>   <servlet-mapping>
>     <servlet-name>documents</servlet-name>
>     <url-pattern>/documents/*</url-pattern>
>   </servlet-mapping>
> ...
> </web-app>
>
>
>
>
> Raj Saini wrote:
>
> >Hi Vladimir,
> >
> >My code is inside a ActionListener of CommandLink component of JSF
> >and that may be the reason it is not working. I am not able to figure
> >out how to forward control to servlet from ActionListener. Can you
> >please tell me how do you forward control to servlet from your JSF page?
> >
> >Regards,
> >
> >Raj
> >
> >On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> >
> >
> >>Hi Raj,
> >>
> >>I look your code. I think, it does not work because you use not pure
> >>сервлет for loading. I do not see heading of your class - similar
> >>that it Faces PageBean?
> >>
> >>
> >
> >
> >
> >
> >>I use a combination JSF pages + simple pure Servlet, listening part
> >>URL for download:
> >>
> >>
> >>
> >>public class Doc_view extends HttpServlet {
> >>
> >>  public void doGet(HttpServletRequest request, HttpServletResponse
> >>response)
> >>          throws ServletException, IOException {
> >>    String uri = request.getPathInfo();
> >>    int pdoc_id=Integer.parseInt(request.getParameter("doc_id"));
> >>    try {
> >>        response.setContentType("application/x-download");
> >>        response.setHeader("content-disposition", "attachment;
> >>name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\"");
> >>      byte[] data = .... ;
> >>      response.setContentLength(data.length);
> >>      response.getOutputStream().write(data);
> >>    } catch (Exception e) {...    }
> >>  }
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>Raj Saini wrote:
> >>
> >>
> >>
> >>>Hi Vladmir,
> >>>
> >>>I tried your suggestion. It did not work for me. I am using apche
> >>>my faces JSF bridge. Does it work for you form a JSF based porlet?
> >>>
> >>>Below the the code snipt of processAction method of command link
> >>>action listener. Can you see if I am missing something?
> >>>
> >>>
> >>>============================
> >>>
> >>>      FacesContext facesContext = FacesContext.getCurrentInstance();
> >>>              String path =
> >>>facesContext.getExternalContext().getInitParameter("uploadDirectory
> >>>Location");
> >>>
> >>>              Map map = facesContext.getExternalContext().getRequestParameterMap();
> >>>              String fileName = (String) map.get("fileName");
> >>>              System.out.println("File URI: " + path+fileName);
> >>>
> >>>              File file = new File(path + fileName);
> >>>              long fileSize =file.length();
> >>>
> >>>              //Set the HTTP headers for foce download the file
> >>>              HttpServletResponse response =
> >>>(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
> >>>              response.setContentType("application/x-download");
> >>>              response.setHeader("content-disposition",
> >>>"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
> >>>              response.setContentLength((int)fileSize);
> >>>==========================================================
> >>>
> >>>Regards,
> >>>
> >>>Raj
> >>>On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>>Hi,
> >>>>try next:
> >>>>
> >>>>response.setContentType("application/x-download");
> >>>>response.setHeader(
> >>>>"content-disposition",
> >>>>"attachment;name=\""+downloadFileName+"\";filename=\""+downloadFil
> >>>>eName+"\"");
> >>>>
> >>>>for me - it's worked exellent in IE, Opera and Mozilla
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>Raj Saini wrote:
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>Hi David,
> >>>>>
> >>>>>I tried it. It does not work.
> >>>>>
> >>>>>Thanks,
> >>>>>
> >>>>>Raj
> >>>>>
> >>>>>On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>>Hi,
> >>>>>>
> >>>>>>try this code:
> >>>>>>
> >>>>>>response.setContentType("binary/download");
> >>>>>>response.setHeader("Content-disposition","attachment;
> >>>>>>filename=xxx.xxx");
> >>>>>>
> >>>>>>before dump the content.
> >>>>>>
> >>>>>>
> >>>>>>Best Regards,
> >>>>>>
> >>>>>>David
> >>>>>>
> >>>>>>
> >>>>>>-----Original Message-----
> >>>>>>From: Raj Saini [mailto:rajsaini@gmail.com]
> >>>>>>Sent: Saturday, April 08, 2006 11:06 PM
> >>>>>>To: Jetspeed Users List
> >>>>>>Subject: Force downloading a file in JSF portlet
> >>>>>>
> >>>>>>Hi,
> >>>>>>
> >>>>>>
> >>>>>>I am building JSF based portlet for downloading a file using
> >>>>>>MyFaces JSF bridge.
> >>>>>>I do the following to make the file force download:
> >>>>>>
> >>>>>>1) Set "content-disposition" header to contain the correct
> >>>>>>filename
> >>>>>>2) Set "content-type" header to "application/octet-stream" or
> >>>>>>something more accurate if the information is present in
> >>>>>>attachment metadata
> >>>>>>3) Dump the content using a ServletOutputStream
> >>>>>>
> >>>>>>When I click on the link to download the file, instead of
> >>>>>>throwing a dialog box for saving/opening the file, browser dumps
> >>>>>>the the binary contents on page. However, this works fine as standalone application.
> >>>>>>
> >>>>>>Is there something extra I need to do to force download file in
> >>>>>>Jetspeed? Am I missing something here?
> >>>>>>
> >>>>>>Regards,
> >>>>>>
> >>>>>>Raj
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>----------------------------------------------------------------
> >>>>>>----- To unsubscribe, e-mail:
> >>>>>>jetspeed-user-unsubscribe@portals.apache.org
> >>>>>>For additional commands, e-mail:
> >>>>>>jetspeed-user-help@portals.apache.org
> >>>>>>
> >>>>>>
> >>>>>>----------------------------------------------------------------
> >>>>>>----- To unsubscribe, e-mail:
> >>>>>>jetspeed-user-unsubscribe@portals.apache.org
> >>>>>>For additional commands, e-mail:
> >>>>>>jetspeed-user-help@portals.apache.org
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>-----------------------------------------------------------------
> >>>>>---- To unsubscribe, e-mail:
> >>>>>jetspeed-user-unsubscribe@portals.apache.org
> >>>>>For additional commands, e-mail:
> >>>>>jetspeed-user-help@portals.apache.org
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>--
> >>>>Vladimir
> >>>>
> >>>>
> >>>>------------------------------------------------------------------
> >>>>--- To unsubscribe, e-mail:
> >>>>jetspeed-user-unsubscribe@portals.apache.org
> >>>>For additional commands, e-mail:
> >>>>jetspeed-user-help@portals.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>-------------------------------------------------------------------
> >>>-- To unsubscribe, e-mail:
> >>>jetspeed-user-unsubscribe@portals.apache.org
> >>>For additional commands, e-mail:
> >>>jetspeed-user-help@portals.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>--
> >>Vladimir
> >>
> >>
> >>--------------------------------------------------------------------
> >>- To unsubscribe, e-mail:
> >>jetspeed-user-unsubscribe@portals.apache.org
> >>For additional commands, e-mail:
> >>jetspeed-user-help@portals.apache.org
> >>
> >>
> >>
> >>
>
>
> --
> Vladimir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Vladimir,

Thanks for you help till now. I feel I am still missing something. I
am not able to forward the control from my JSF page to servlet. My
servlet is configured fine and it is working standalone.

I searched the web for help on how to forward request to a servlet
from JSF page and based on it I call an action method in my JSF page
and action method returns a String.

<code>
 public String download() {
    	System.out.println("Inside download method");
    	return "/knowledge-base/download";
    }
</code>

However, request is never forwarded to servlet. Can you throw some
light? Can you tell me how do you forward request from JSF page to
servlet? What do you specify in the action attribute of your
CommandLink component?

Thanks,

Raj

On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> 8-O
>
> It's simple - need add to web.xml next elements:
>
> <web-app>
> ...
>   <servlet>
>     <servlet-name>documents</servlet-name>
>     <servlet-class>asoft.web.Doc_view</servlet-class>
>     <load-on-startup>1</load-on-startup>
>   </servlet>
> ...
>
>
>   <servlet-mapping>
>     <servlet-name>documents</servlet-name>
>     <url-pattern>/documents/*</url-pattern>
>   </servlet-mapping>
> ...
> </web-app>
>
>
>
>
> Raj Saini wrote:
>
> >Hi Vladimir,
> >
> >My code is inside a ActionListener of CommandLink component of JSF and
> >that may be the reason it is not working. I am not able to figure out
> >how to forward control to servlet from ActionListener. Can you please
> >tell me how do you forward control to servlet from your JSF page?
> >
> >Regards,
> >
> >Raj
> >
> >On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> >
> >
> >>Hi Raj,
> >>
> >>I look your code. I think, it does not work because you use not pure
> >>сервлет for loading. I do not see heading of your class - similar that
> >>it Faces PageBean?
> >>
> >>
> >
> >
> >
> >
> >>I use a combination JSF pages + simple pure Servlet, listening part URL
> >>for download:
> >>
> >>
> >>
> >>public class Doc_view extends HttpServlet {
> >>
> >>  public void doGet(HttpServletRequest request, HttpServletResponse
> >>response)
> >>          throws ServletException, IOException {
> >>    String uri = request.getPathInfo();
> >>    int pdoc_id=Integer.parseInt(request.getParameter("doc_id"));
> >>    try {
> >>        response.setContentType("application/x-download");
> >>        response.setHeader("content-disposition", "attachment;
> >>name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\"");
> >>      byte[] data = .... ;
> >>      response.setContentLength(data.length);
> >>      response.getOutputStream().write(data);
> >>    } catch (Exception e) {...    }
> >>  }
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>Raj Saini wrote:
> >>
> >>
> >>
> >>>Hi Vladmir,
> >>>
> >>>I tried your suggestion. It did not work for me. I am using apche my
> >>>faces JSF bridge. Does it work for you form a JSF based porlet?
> >>>
> >>>Below the the code snipt of processAction method of command link
> >>>action listener. Can you see if I am missing something?
> >>>
> >>>
> >>>============================
> >>>
> >>>      FacesContext facesContext = FacesContext.getCurrentInstance();
> >>>              String path =
> >>>facesContext.getExternalContext().getInitParameter("uploadDirectoryLocation");
> >>>
> >>>              Map map = facesContext.getExternalContext().getRequestParameterMap();
> >>>              String fileName = (String) map.get("fileName");
> >>>              System.out.println("File URI: " + path+fileName);
> >>>
> >>>              File file = new File(path + fileName);
> >>>              long fileSize =file.length();
> >>>
> >>>              //Set the HTTP headers for foce download the file
> >>>              HttpServletResponse response =
> >>>(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
> >>>              response.setContentType("application/x-download");
> >>>              response.setHeader("content-disposition",
> >>>"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
> >>>              response.setContentLength((int)fileSize);
> >>>==========================================================
> >>>
> >>>Regards,
> >>>
> >>>Raj
> >>>On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>>Hi,
> >>>>try next:
> >>>>
> >>>>response.setContentType("application/x-download");
> >>>>response.setHeader(
> >>>>"content-disposition",
> >>>>"attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");
> >>>>
> >>>>for me - it's worked exellent in IE, Opera and Mozilla
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>Raj Saini wrote:
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>Hi David,
> >>>>>
> >>>>>I tried it. It does not work.
> >>>>>
> >>>>>Thanks,
> >>>>>
> >>>>>Raj
> >>>>>
> >>>>>On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>>Hi,
> >>>>>>
> >>>>>>try this code:
> >>>>>>
> >>>>>>response.setContentType("binary/download");
> >>>>>>response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
> >>>>>>
> >>>>>>before dump the content.
> >>>>>>
> >>>>>>
> >>>>>>Best Regards,
> >>>>>>
> >>>>>>David
> >>>>>>
> >>>>>>
> >>>>>>-----Original Message-----
> >>>>>>From: Raj Saini [mailto:rajsaini@gmail.com]
> >>>>>>Sent: Saturday, April 08, 2006 11:06 PM
> >>>>>>To: Jetspeed Users List
> >>>>>>Subject: Force downloading a file in JSF portlet
> >>>>>>
> >>>>>>Hi,
> >>>>>>
> >>>>>>
> >>>>>>I am building JSF based portlet for downloading a file using MyFaces JSF
> >>>>>>bridge.
> >>>>>>I do the following to make the file force download:
> >>>>>>
> >>>>>>1) Set "content-disposition" header to contain the correct filename
> >>>>>>2) Set "content-type" header to "application/octet-stream" or something more
> >>>>>>accurate if the information is present in attachment metadata
> >>>>>>3) Dump the content using a ServletOutputStream
> >>>>>>
> >>>>>>When I click on the link to download the file, instead of throwing a dialog
> >>>>>>box for saving/opening the file, browser dumps the the binary contents on
> >>>>>>page. However, this works fine as standalone application.
> >>>>>>
> >>>>>>Is there something extra I need to do to force download file in Jetspeed? Am
> >>>>>>I missing something here?
> >>>>>>
> >>>>>>Regards,
> >>>>>>
> >>>>>>Raj
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>---------------------------------------------------------------------
> >>>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>>>>
> >>>>>>
> >>>>>>---------------------------------------------------------------------
> >>>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>---------------------------------------------------------------------
> >>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>--
> >>>>Vladimir
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>--
> >>Vladimir
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>
> >>
> >>
> >>
>
>
> --
> Vladimir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

Re: Force downloading a file in JSF portlet

Posted by Vladimir Figurov <VF...@asia-soft.kz>.
8-O

It's simple - need add to web.xml next elements:

<web-app>
...
  <servlet>
    <servlet-name>documents</servlet-name>
    <servlet-class>asoft.web.Doc_view</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
...


  <servlet-mapping>
    <servlet-name>documents</servlet-name>
    <url-pattern>/documents/*</url-pattern>
  </servlet-mapping>
...
</web-app>




Raj Saini wrote:

>Hi Vladimir,
>
>My code is inside a ActionListener of CommandLink component of JSF and
>that may be the reason it is not working. I am not able to figure out
>how to forward control to servlet from ActionListener. Can you please
>tell me how do you forward control to servlet from your JSF page?
>
>Regards,
>
>Raj
>
>On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
>  
>
>>Hi Raj,
>>
>>I look your code. I think, it does not work because you use not pure
>>сервлет for loading. I do not see heading of your class - similar that
>>it Faces PageBean?
>>    
>>
>
>
>  
>
>>I use a combination JSF pages + simple pure Servlet, listening part URL
>>for download:
>>
>>
>>
>>public class Doc_view extends HttpServlet {
>>
>>  public void doGet(HttpServletRequest request, HttpServletResponse
>>response)
>>          throws ServletException, IOException {
>>    String uri = request.getPathInfo();
>>    int pdoc_id=Integer.parseInt(request.getParameter("doc_id"));
>>    try {
>>        response.setContentType("application/x-download");
>>        response.setHeader("content-disposition", "attachment;
>>name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\"");
>>      byte[] data = .... ;
>>      response.setContentLength(data.length);
>>      response.getOutputStream().write(data);
>>    } catch (Exception e) {...    }
>>  }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>Raj Saini wrote:
>>
>>    
>>
>>>Hi Vladmir,
>>>
>>>I tried your suggestion. It did not work for me. I am using apche my
>>>faces JSF bridge. Does it work for you form a JSF based porlet?
>>>
>>>Below the the code snipt of processAction method of command link
>>>action listener. Can you see if I am missing something?
>>>
>>>
>>>============================
>>>
>>>      FacesContext facesContext = FacesContext.getCurrentInstance();
>>>              String path =
>>>facesContext.getExternalContext().getInitParameter("uploadDirectoryLocation");
>>>
>>>              Map map = facesContext.getExternalContext().getRequestParameterMap();
>>>              String fileName = (String) map.get("fileName");
>>>              System.out.println("File URI: " + path+fileName);
>>>
>>>              File file = new File(path + fileName);
>>>              long fileSize =file.length();
>>>
>>>              //Set the HTTP headers for foce download the file
>>>              HttpServletResponse response =
>>>(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
>>>              response.setContentType("application/x-download");
>>>              response.setHeader("content-disposition",
>>>"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
>>>              response.setContentLength((int)fileSize);
>>>==========================================================
>>>
>>>Regards,
>>>
>>>Raj
>>>On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
>>>
>>>
>>>      
>>>
>>>>Hi,
>>>>try next:
>>>>
>>>>response.setContentType("application/x-download");
>>>>response.setHeader(
>>>>"content-disposition",
>>>>"attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");
>>>>
>>>>for me - it's worked exellent in IE, Opera and Mozilla
>>>>
>>>>
>>>>
>>>>
>>>>Raj Saini wrote:
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>Hi David,
>>>>>
>>>>>I tried it. It does not work.
>>>>>
>>>>>Thanks,
>>>>>
>>>>>Raj
>>>>>
>>>>>On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>try this code:
>>>>>>
>>>>>>response.setContentType("binary/download");
>>>>>>response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
>>>>>>
>>>>>>before dump the content.
>>>>>>
>>>>>>
>>>>>>Best Regards,
>>>>>>
>>>>>>David
>>>>>>
>>>>>>
>>>>>>-----Original Message-----
>>>>>>From: Raj Saini [mailto:rajsaini@gmail.com]
>>>>>>Sent: Saturday, April 08, 2006 11:06 PM
>>>>>>To: Jetspeed Users List
>>>>>>Subject: Force downloading a file in JSF portlet
>>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>
>>>>>>I am building JSF based portlet for downloading a file using MyFaces JSF
>>>>>>bridge.
>>>>>>I do the following to make the file force download:
>>>>>>
>>>>>>1) Set "content-disposition" header to contain the correct filename
>>>>>>2) Set "content-type" header to "application/octet-stream" or something more
>>>>>>accurate if the information is present in attachment metadata
>>>>>>3) Dump the content using a ServletOutputStream
>>>>>>
>>>>>>When I click on the link to download the file, instead of throwing a dialog
>>>>>>box for saving/opening the file, browser dumps the the binary contents on
>>>>>>page. However, this works fine as standalone application.
>>>>>>
>>>>>>Is there something extra I need to do to force download file in Jetspeed? Am
>>>>>>I missing something here?
>>>>>>
>>>>>>Regards,
>>>>>>
>>>>>>Raj
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>--
>>>>Vladimir
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>
>>>
>>>
>>>
>>>      
>>>
>>--
>>Vladimir
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>
>>
>>    
>>


-- 
Vladimir


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


Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Hi Vladimir,

My code is inside a ActionListener of CommandLink component of JSF and
that may be the reason it is not working. I am not able to figure out
how to forward control to servlet from ActionListener. Can you please
tell me how do you forward control to servlet from your JSF page?

Regards,

Raj

On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> Hi Raj,
>
> I look your code. I think, it does not work because you use not pure
> сервлет for loading. I do not see heading of your class - similar that
> it Faces PageBean?


>
> I use a combination JSF pages + simple pure Servlet, listening part URL
> for download:
>
>
>
> public class Doc_view extends HttpServlet {
>
>   public void doGet(HttpServletRequest request, HttpServletResponse
> response)
>           throws ServletException, IOException {
>     String uri = request.getPathInfo();
>     int pdoc_id=Integer.parseInt(request.getParameter("doc_id"));
>     try {
>         response.setContentType("application/x-download");
>         response.setHeader("content-disposition", "attachment;
> name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\"");
>       byte[] data = .... ;
>       response.setContentLength(data.length);
>       response.getOutputStream().write(data);
>     } catch (Exception e) {...    }
>   }
>
>
>
>
>
>
>
>
>
>
> Raj Saini wrote:
>
> >Hi Vladmir,
> >
> >I tried your suggestion. It did not work for me. I am using apche my
> >faces JSF bridge. Does it work for you form a JSF based porlet?
> >
> >Below the the code snipt of processAction method of command link
> >action listener. Can you see if I am missing something?
> >
> >
> >============================
> >
> >       FacesContext facesContext = FacesContext.getCurrentInstance();
> >               String path =
> >facesContext.getExternalContext().getInitParameter("uploadDirectoryLocation");
> >
> >               Map map = facesContext.getExternalContext().getRequestParameterMap();
> >               String fileName = (String) map.get("fileName");
> >               System.out.println("File URI: " + path+fileName);
> >
> >               File file = new File(path + fileName);
> >               long fileSize =file.length();
> >
> >               //Set the HTTP headers for foce download the file
> >               HttpServletResponse response =
> >(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
> >               response.setContentType("application/x-download");
> >               response.setHeader("content-disposition",
> >"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
> >               response.setContentLength((int)fileSize);
> >==========================================================
> >
> >Regards,
> >
> >Raj
> >On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> >
> >
> >>Hi,
> >>try next:
> >>
> >>response.setContentType("application/x-download");
> >>response.setHeader(
> >> "content-disposition",
> >> "attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");
> >>
> >>for me - it's worked exellent in IE, Opera and Mozilla
> >>
> >>
> >>
> >>
> >>Raj Saini wrote:
> >>
> >>
> >>
> >>>Hi David,
> >>>
> >>>I tried it. It does not work.
> >>>
> >>>Thanks,
> >>>
> >>>Raj
> >>>
> >>>On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>>Hi,
> >>>>
> >>>>try this code:
> >>>>
> >>>>response.setContentType("binary/download");
> >>>>response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
> >>>>
> >>>>before dump the content.
> >>>>
> >>>>
> >>>>Best Regards,
> >>>>
> >>>>David
> >>>>
> >>>>
> >>>>-----Original Message-----
> >>>>From: Raj Saini [mailto:rajsaini@gmail.com]
> >>>>Sent: Saturday, April 08, 2006 11:06 PM
> >>>>To: Jetspeed Users List
> >>>>Subject: Force downloading a file in JSF portlet
> >>>>
> >>>>Hi,
> >>>>
> >>>>
> >>>>I am building JSF based portlet for downloading a file using MyFaces JSF
> >>>>bridge.
> >>>>I do the following to make the file force download:
> >>>>
> >>>>1) Set "content-disposition" header to contain the correct filename
> >>>>2) Set "content-type" header to "application/octet-stream" or something more
> >>>>accurate if the information is present in attachment metadata
> >>>>3) Dump the content using a ServletOutputStream
> >>>>
> >>>>When I click on the link to download the file, instead of throwing a dialog
> >>>>box for saving/opening the file, browser dumps the the binary contents on
> >>>>page. However, this works fine as standalone application.
> >>>>
> >>>>Is there something extra I need to do to force download file in Jetspeed? Am
> >>>>I missing something here?
> >>>>
> >>>>Regards,
> >>>>
> >>>>Raj
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>--
> >>Vladimir
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >
> >
> >
> >
>
>
> --
> Vladimir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

Re: Force downloading a file in JSF portlet

Posted by Vladimir Figurov <VF...@asia-soft.kz>.
Hi Raj,

I look your code. I think, it does not work because you use not pure 
сервлет for loading. I do not see heading of your class - similar that 
it Faces PageBean?

I use a combination JSF pages + simple pure Servlet, listening part URL 
for download:



public class Doc_view extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse 
response)
          throws ServletException, IOException {
    String uri = request.getPathInfo();
    int pdoc_id=Integer.parseInt(request.getParameter("doc_id"));
    try {
        response.setContentType("application/x-download");
        response.setHeader("content-disposition", "attachment; 
name=\""+downloadFileName+"\"; filename=\""+downloadFileName+"\"");
      byte[] data = .... ;
      response.setContentLength(data.length);
      response.getOutputStream().write(data);
    } catch (Exception e) {...    }
  }










Raj Saini wrote:

>Hi Vladmir,
>
>I tried your suggestion. It did not work for me. I am using apche my
>faces JSF bridge. Does it work for you form a JSF based porlet?
>
>Below the the code snipt of processAction method of command link
>action listener. Can you see if I am missing something?
>
>
>============================
>
>	FacesContext facesContext = FacesContext.getCurrentInstance();
>		String path =
>facesContext.getExternalContext().getInitParameter("uploadDirectoryLocation");
>
>		Map map = facesContext.getExternalContext().getRequestParameterMap();
>		String fileName = (String) map.get("fileName");
>		System.out.println("File URI: " + path+fileName);
>		
>		File file = new File(path + fileName);
>		long fileSize =file.length();
>	
>		//Set the HTTP headers for foce download the file
>		HttpServletResponse response =
>(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
>		response.setContentType("application/x-download");
>		response.setHeader("content-disposition",
>"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
>		response.setContentLength((int)fileSize);
>==========================================================
>
>Regards,
>
>Raj
>On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
>  
>
>>Hi,
>>try next:
>>
>>response.setContentType("application/x-download");
>>response.setHeader(
>> "content-disposition",
>> "attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");
>>
>>for me - it's worked exellent in IE, Opera and Mozilla
>>
>>
>>
>>
>>Raj Saini wrote:
>>
>>    
>>
>>>Hi David,
>>>
>>>I tried it. It does not work.
>>>
>>>Thanks,
>>>
>>>Raj
>>>
>>>On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
>>>
>>>
>>>      
>>>
>>>>Hi,
>>>>
>>>>try this code:
>>>>
>>>>response.setContentType("binary/download");
>>>>response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
>>>>
>>>>before dump the content.
>>>>
>>>>
>>>>Best Regards,
>>>>
>>>>David
>>>>
>>>>
>>>>-----Original Message-----
>>>>From: Raj Saini [mailto:rajsaini@gmail.com]
>>>>Sent: Saturday, April 08, 2006 11:06 PM
>>>>To: Jetspeed Users List
>>>>Subject: Force downloading a file in JSF portlet
>>>>
>>>>Hi,
>>>>
>>>>
>>>>I am building JSF based portlet for downloading a file using MyFaces JSF
>>>>bridge.
>>>>I do the following to make the file force download:
>>>>
>>>>1) Set "content-disposition" header to contain the correct filename
>>>>2) Set "content-type" header to "application/octet-stream" or something more
>>>>accurate if the information is present in attachment metadata
>>>>3) Dump the content using a ServletOutputStream
>>>>
>>>>When I click on the link to download the file, instead of throwing a dialog
>>>>box for saving/opening the file, browser dumps the the binary contents on
>>>>page. However, this works fine as standalone application.
>>>>
>>>>Is there something extra I need to do to force download file in Jetspeed? Am
>>>>I missing something here?
>>>>
>>>>Regards,
>>>>
>>>>Raj
>>>>
>>>>
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>>
>>>
>>>
>>>
>>>      
>>>
>>--
>>Vladimir
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
>  
>


-- 
Vladimir


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


Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Hi Vladmir,

I tried your suggestion. It did not work for me. I am using apche my
faces JSF bridge. Does it work for you form a JSF based porlet?

Below the the code snipt of processAction method of command link
action listener. Can you see if I am missing something?


============================

	FacesContext facesContext = FacesContext.getCurrentInstance();
		String path =
facesContext.getExternalContext().getInitParameter("uploadDirectoryLocation");

		Map map = facesContext.getExternalContext().getRequestParameterMap();
		String fileName = (String) map.get("fileName");
		System.out.println("File URI: " + path+fileName);
		
		File file = new File(path + fileName);
		long fileSize =file.length();
	
		//Set the HTTP headers for foce download the file
		HttpServletResponse response =
(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
		response.setContentType("application/x-download");
		response.setHeader("content-disposition",
"attachment;name=\""+fileName+"\";filename=\""+fileName+"\"");
		response.setContentLength((int)fileSize);
==========================================================

Regards,

Raj
On 4/10/06, Vladimir Figurov <VF...@asia-soft.kz> wrote:
> Hi,
> try next:
>
> response.setContentType("application/x-download");
> response.setHeader(
>  "content-disposition",
>  "attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");
>
> for me - it's worked exellent in IE, Opera and Mozilla
>
>
>
>
> Raj Saini wrote:
>
> >Hi David,
> >
> >I tried it. It does not work.
> >
> >Thanks,
> >
> >Raj
> >
> >On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
> >
> >
> >>Hi,
> >>
> >>try this code:
> >>
> >>response.setContentType("binary/download");
> >>response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
> >>
> >>before dump the content.
> >>
> >>
> >>Best Regards,
> >>
> >>David
> >>
> >>
> >>-----Original Message-----
> >>From: Raj Saini [mailto:rajsaini@gmail.com]
> >>Sent: Saturday, April 08, 2006 11:06 PM
> >>To: Jetspeed Users List
> >>Subject: Force downloading a file in JSF portlet
> >>
> >>Hi,
> >>
> >>
> >>I am building JSF based portlet for downloading a file using MyFaces JSF
> >>bridge.
> >>I do the following to make the file force download:
> >>
> >>1) Set "content-disposition" header to contain the correct filename
> >>2) Set "content-type" header to "application/octet-stream" or something more
> >>accurate if the information is present in attachment metadata
> >>3) Dump the content using a ServletOutputStream
> >>
> >>When I click on the link to download the file, instead of throwing a dialog
> >>box for saving/opening the file, browser dumps the the binary contents on
> >>page. However, this works fine as standalone application.
> >>
> >>Is there something extra I need to do to force download file in Jetspeed? Am
> >>I missing something here?
> >>
> >>Regards,
> >>
> >>Raj
> >>
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> >For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >
> >
> >
> >
>
>
> --
> Vladimir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

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


Re: Force downloading a file in JSF portlet

Posted by Vladimir Figurov <VF...@asia-soft.kz>.
Hi,
try next:

response.setContentType("application/x-download");
response.setHeader(
 "content-disposition",
 "attachment;name=\""+downloadFileName+"\";filename=\""+downloadFileName+"\"");

for me - it's worked exellent in IE, Opera and Mozilla




Raj Saini wrote:

>Hi David,
>
>I tried it. It does not work.
>
>Thanks,
>
>Raj
>
>On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
>  
>
>>Hi,
>>
>>try this code:
>>
>>response.setContentType("binary/download");
>>response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
>>
>>before dump the content.
>>
>>
>>Best Regards,
>>
>>David
>>
>>
>>-----Original Message-----
>>From: Raj Saini [mailto:rajsaini@gmail.com]
>>Sent: Saturday, April 08, 2006 11:06 PM
>>To: Jetspeed Users List
>>Subject: Force downloading a file in JSF portlet
>>
>>Hi,
>>
>>
>>I am building JSF based portlet for downloading a file using MyFaces JSF
>>bridge.
>>I do the following to make the file force download:
>>
>>1) Set "content-disposition" header to contain the correct filename
>>2) Set "content-type" header to "application/octet-stream" or something more
>>accurate if the information is present in attachment metadata
>>3) Dump the content using a ServletOutputStream
>>
>>When I click on the link to download the file, instead of throwing a dialog
>>box for saving/opening the file, browser dumps the the binary contents on
>>page. However, this works fine as standalone application.
>>
>>Is there something extra I need to do to force download file in Jetspeed? Am
>>I missing something here?
>>
>>Regards,
>>
>>Raj
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
>  
>


-- 
Vladimir


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


Re: Force downloading a file in JSF portlet

Posted by Raj Saini <ra...@gmail.com>.
Hi David,

I tried it. It does not work.

Thanks,

Raj

On 4/9/06, gexiangdong@gmail.com <ge...@gmail.com> wrote:
> Hi,
>
> try this code:
>
> response.setContentType("binary/download");
> response.setHeader("Content-disposition","attachment; filename=xxx.xxx");
>
> before dump the content.
>
>
> Best Regards,
>
> David
>
>
> -----Original Message-----
> From: Raj Saini [mailto:rajsaini@gmail.com]
> Sent: Saturday, April 08, 2006 11:06 PM
> To: Jetspeed Users List
> Subject: Force downloading a file in JSF portlet
>
> Hi,
>
>
> I am building JSF based portlet for downloading a file using MyFaces JSF
> bridge.
> I do the following to make the file force download:
>
> 1) Set "content-disposition" header to contain the correct filename
> 2) Set "content-type" header to "application/octet-stream" or something more
> accurate if the information is present in attachment metadata
> 3) Dump the content using a ServletOutputStream
>
> When I click on the link to download the file, instead of throwing a dialog
> box for saving/opening the file, browser dumps the the binary contents on
> page. However, this works fine as standalone application.
>
> Is there something extra I need to do to force download file in Jetspeed? Am
> I missing something here?
>
> Regards,
>
> Raj
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

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


Re: JSF portlet - how to getting the Jetspeed functions?

Posted by Vladimir Figurov <VF...@asia-soft.kz>.
Addons:

I am using a Jestspeed 1.6 with fusion.
I am a try building JSF based portlet for master-detail tables.


Necessary, that after click on the button (or link) the new window with 
details opened. Without any portal's elements - as Print mode.
If I use a next method:
      <h:commandLink id="clnkShowReport"
                      target="_blank"
                      action="reportbody"
                      value="Show report"/>
then I getted a new window, but with full portal's elements (Logo, menu, 
...)


If I use another method:
     <h:outputLink id="olnkShowReport"
                   target="_blank" 
value="#{facesContext.externalContext.requestContextPath}/eqreport_body.jsf">
       <f:verbatim>Show report</f:verbatim>
     </h:outputLink>

then I getting a Error:
javax.faces.FacesException: Unsupported context type 
org.apache.catalina.core.ApplicationContextFacade
	org.apache.portals.bridges.jsf.FacesContextFactoryImpl.getFacesContext(FacesContextFactoryImpl.java:58)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:100)






In JSP-portlets there is a full access to all set of Jetspeed's functions.

But JSF-Portlets - is BLACK BOX.   %(
I cannot find access to jetspeed functions - all is limited a Pluto
"sandbox" and Portlet-JSR 168 API.
And this API do not allow to operate modes of construction of the target
(out) screen from templates, change templates, ets.

Any body know there I can find a docs, manual for work with JSF-Portlets 
& Jetspeed?


Vladimir


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


JSF portlet - how to getting the Jetspeed functions?

Posted by Vladimir Figurov <VF...@asia-soft.kz>.
Hi,

I am using a Jestspeed 1.6 with fusion.
I am a try building JSF based portlet for master-detail tables.

In JSP-portlets there is a full access to all set of Jetspeed's functions.

But JSF-Portlets - is BLACK BOX.   %(
I cannot find access to jetspeed functions - all is limited a Pluto 
"sandbox" and Portlet-JSR 168 API.
And this API do not allow to operate modes of construction of the target 
(out) screen from templates, change templates, ets.

Any know there I can find a docs, manual?


Vladimir

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


RE: Force downloading a file in JSF portlet

Posted by ge...@gmail.com.
Hi,

try this code:

response.setContentType("binary/download"); 
response.setHeader("Content-disposition","attachment; filename=xxx.xxx");

before dump the content.


Best Regards,

David


-----Original Message-----
From: Raj Saini [mailto:rajsaini@gmail.com] 
Sent: Saturday, April 08, 2006 11:06 PM
To: Jetspeed Users List
Subject: Force downloading a file in JSF portlet 

Hi,


I am building JSF based portlet for downloading a file using MyFaces JSF
bridge.
I do the following to make the file force download:

1) Set "content-disposition" header to contain the correct filename
2) Set "content-type" header to "application/octet-stream" or something more
accurate if the information is present in attachment metadata
3) Dump the content using a ServletOutputStream

When I click on the link to download the file, instead of throwing a dialog
box for saving/opening the file, browser dumps the the binary contents on
page. However, this works fine as standalone application.

Is there something extra I need to do to force download file in Jetspeed? Am
I missing something here?

Regards,

Raj




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


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