|
Home > Archive > WebSphere Portal Server > November 2006 > Save Dialog does not appear in JSF Portlet
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Save Dialog does not appear in JSF Portlet
|
|
|
| Hi All,
I have a JSF portlet where i want to save the contents of my Text area on the click of a button to a word document.(IBM Websphere portal) <h:inputTextarea id="text1" value="#{pc_TextAreaView.textAreaValue}" rows="10" cols="50" />
<h:commandButton id="save" value="Save As Word" action="#{pc_TextAreaView.SaveAsWord}"/>
In my page bean i have written the follwoing code but the response.setHeader() doesn't seem to work.I am not getting any pop dialog and i cannot save my file.
Please help me to get this thing work.
Code:
=====
public String SaveAsWord() { FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType("application/vnd.ms-word");
response.setHeader("Content-Disposition", "attachment;filename=myfile.doc");
response.setHeader("Cache-Control", "no-cache");
try{
byte[] buf=new byte[4*1024];
InputStream inStream=new ByteArrayInputStream(textAreaValue.getBytes()); OutputStream outStream=response.getOutputStream();
int sizeRead;
while ( ( sizeRead=inStream.read(buf, 0, buf.length) ) != -1 ) { outStream.write(buf, 0, sizeRead); }
inStream.close();
outStream.close(); }
catch(IOException ex){ ex.printStackTrace(); }
return null; }
| |
| yurykats 2006-11-21, 1:20 pm |
| As far as I know, you can't change content type or headers in a portlet response. The entire response is object is owned by the Portal server and the indivisual portlets can't change it.
| |
|
| Hi yurykats,
Thanks for your reply.
i just read the JSR-168 specification where it mentions that you cannot set or access the response headers in a portlet.
Can you suggest any workaround.
Best Regards,
Pallavi
| |
| yurykats 2006-11-22, 1:18 pm |
| If think if you created a separate servlet you'd be able to manipulate headers.
|
|
|
|
|