Hi Pallavi,
 
you took a more elegant way to forward to te servlet. I will take this
also for my version next. 
 
what is also different, I do target the form to "_blank" to open a new
window. Also I implemented the processing in 
 
  protected void service(final HttpServletRequest request, final
HttpServletResponse response)  of HttpServlet
 
but I can not see, why you get entire page content instead of the
textArea, sorry.
 
Regards,
 
Stephan

________________________________

Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Gesendet: Donnerstag, 23. November 2006 14:35
An: [email protected]
Betreff: RE: response.Header() not working in JSF Portlet


Hi David,
             Thank you for your suggestions.
             I have now included the servlet and JSF portlet in the same
war file and deployed on Websphere Portal Server.
             But currently the saving of the text area contents into
word document is happening but it saves the entire portlet page instead
of only the text area contents.
             Could you help me in my last minute hitch with the code.
             
            1) JSF Portlet Page:
             ------------------------
             <h:inputTextarea id="text1"
value="#{pc_TextAreaView.textAreaValue}" rows="10" cols="50" />
             <h:commandButton id="save1" value="Save with Servlet"
action="#{pc_TextAreaView.SaveAsWord}" />
 
            2) Backing bean Save method: 
             ----------------------------------------
             public void SaveAsWord() {
  
              System.out.println("I invoke this");
              FacesContext context = FacesContext.getCurrentInstance();
              ExternalContext ctx = context.getExternalContext();
              try{
              HttpServletResponse response =
(HttpServletResponse)ctx.getResponse();
              HttpServletRequest request =
(HttpServletRequest)ctx.getRequest();
              RequestDispatcher view =
request.getRequestDispatcher("/WordServ1");
              view.forward(request,response);
              }catch(Exception e){e.printStackTrace();}
 
             3) Servlet to handle the saving in word document
 
------------------------------------------------------------------
       protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
  
       FacesContext facesContext = FacesContext.getCurrentInstance();
       ValueBinding vb =
facesContext.getApplication().createValueBinding("#{pc_TextAreaView}");
       TextAreaView mybean = (TextAreaView) vb.getValue(facesContext);
       String mytextarea = mybean.getTextAreaValue();
         
       String filen = "default.doc";
       response.setContentType("application/vnd.ms-word");
       response.setHeader(
"content-disposition","attachment;name=\""+filen+"\";filename=\""+filen+
"\""); 
       response.setHeader("Cache-Control", "no-cache");
        try{
       byte[] buf=new byte[4*1024];
       InputStream inStream=new
ByteArrayInputStream(mytextarea.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();} 
        } 
       }
              
Best Regards,
Pallavi     
  
             

________________________________

From: Nebinger, David [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 22, 2006 8:25 PM
To: MyFaces Discussion
Subject: RE: response.Header() not working in JSF Portlet


To expand on what Stephan provided, in order to share application scope
between your JSF application and a non-JSF servlet, they need to be
deployed in the same war file and entered in the same web.xml.
 
Combining them in this way will provide the connectivity you'd need
based upon Stephan's original response.

        -----Original Message-----
        From: Strittmatter, Stephan
[mailto:[EMAIL PROTECTED]
        Sent: Wednesday, November 22, 2006 6:49 AM
        To: MyFaces Discussion
        Subject: AW: response.Header() not working in JSF Portlet
        
        
        Hi Pallavi,
         
        I use Liferay on Tomcat. The servlet I included within my
portlet war. Not in a separate war.
         
        Sorry for my short answer, but we have currently system tests
with our customer...
         
        Regards, Stephan

________________________________

        Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
        Gesendet: Mittwoch, 22. November 2006 08:08
        An: [email protected]
        Betreff: RE: response.Header() not working in JSF Portlet
        
        
        Hi Stephan,
                         
                         My concepts are not very clear regarding the
portal server.
                         I am using RAD as my IDE and Wepsphere portal
server and application server(WAS).
                         Which Portal server are you using.Are you using
the same combination.
                         I wanted to know whether you are creating a
seperate war file to deploy your servlet on WAS.
                         Then invoking a call to your servlet from your
portlet.
                         Can you show me some light on this grey area.
         
        Best Regards,
        Pallavi
        
________________________________

        From: Strittmatter, Stephan
[mailto:[EMAIL PROTECTED] 
        Sent: Tuesday, November 21, 2006 9:29 PM
        To: MyFaces Discussion
        Subject: AW: response.Header() not working in JSF Portlet
        
        
        Hi Pallavi,
         
        within a portlet it is not allowed to chenge the response
header. Otherwise a portlet would damage the portal around your portlet.
         
        I had this problem also and created a servlet, which I assigned
with the special extention. The only problem was, that I had to include
the part in a verbatim tag to have a form with an own defined target
probably there is a different more elegant way...:
         
        <f:verbatim>

        <form action="${request.contextPath}/download.xml"
target="_blank" method="post">

        <input type="submit" value="Download" title="Download XML file"
id="execute" style="width:7em;" class="portlet-form-button" /> 

        <input type="hidden" name="execute" value="execute" />

        </form>

        </f:verbatim>
        

        
        In the web.xml you have to define then the servlet and assign it
to the extention.
         
        In the servlet you can access the backing bean by following to
get some values:
         
        FacesContext c = FacesContext.getCurrentInstance();

        Application application = c.getApplication();

        MyBackingBean bBean= (MyBackingBean)
application.createValueBinding("#{MyBackingBean}").getValue(c);

         
        Regards,
         
        Stephan
________________________________

        Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
        Gesendet: Montag, 20. November 2006 12:25
        An: [email protected]
        Betreff: response.Header() not working 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 let me know what is wrong in this code snippet.How can i
make it work in my portlet.
         
        
========================================================================
=======
         
        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;
          }
         
        Best Regards,
        Pallavi 

          

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com
        

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com
        


The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com
        

Reply via email to