Re: JSF servlet request in action method or navigation rule to get binary servlet data?
I think that what Andreas is doing is: (1) access a JSF page -- renders html (2) click on command-component in page, causing a submit (3) in action-handler method, send an http-redirect to the browser (4) browser then does a GET to the redirect address, which maps to a servlet (5) the servlet generates a PDF as response, with appropriate http-headers (6) the server sees that the response mime-type is not HTML, so creates a new window to hold the PDF. The original browser window is left with the same HTML it had at (1) The browser window has simply not changed at all since (1), although a JSF lifecycle has run on the server. So of course any messages are still displayed. Andreas, I have had to do something similar in the past, but took a different approach. In the action-handler method I just put some data in session-scope, and then rendered a JSF page that contains some javascript to do a GET request to the pdf-generation servlet (a META refresh tag might also work). The PDF servlet then used the session-scoped data to generate the appropriate PDF document. Regards, Simon Bernd Bohmann schrieb: Hello Andreas, is your action immediate=true ? Regards Bernd Andreas Niemeyer schrieb: yippi :) Thank you all! Regards, Andreas Richard Yee schrieb: Try using divelement.style.display=none Regards, Richard On Wed, Dec 10, 2008 at 6:27 AM, Andreas Niemeyer [EMAIL PROTECTED] wrote: Hi, It works. The only problem is the left space from the invisible div tag. Regards, Andreas div id=error_messages style=color: darkred;visibility: visible t:messages id=error_messages showDetail=true showSummary=false / /div h:commandButton id=reportbutton onclick=clearMessages('error_messages') value=#{msgs.CreateReportButton} action=#{pdfreport.createPDFReport} / JavaScript: function clearMessages(aMessagesID) { var divelement = document.getElementById(aMessagesID); divelement.style.visibility='hidden'; } Andreas Niemeyer schrieb: Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Simon, hello Bernd, It's exactly what I did. I put some session data in the session scope for the servlet. Your approach sounds good. More than one solution now available :) @Bernd: for this case with the redirect in the action method it makes no difference for the lifecycle behaviour. Yes I tried it, but.. The variant with the JavaScript to `clear' the faces messages works fine and was at least the simplest. When validation in that action method fails, new faces messages appears again, the page is reloaded and the div css property for visibility is as it was declared (without that property) Thank you all for your help! Regards, Andreas Simon Kitching schrieb: I think that what Andreas is doing is: (1) access a JSF page -- renders html (2) click on command-component in page, causing a submit (3) in action-handler method, send an http-redirect to the browser (4) browser then does a GET to the redirect address, which maps to a servlet (5) the servlet generates a PDF as response, with appropriate http-headers (6) the server sees that the response mime-type is not HTML, so creates a new window to hold the PDF. The original browser window is left with the same HTML it had at (1) The browser window has simply not changed at all since (1), although a JSF lifecycle has run on the server. So of course any messages are still displayed. Andreas, I have had to do something similar in the past, but took a different approach. In the action-handler method I just put some data in session-scope, and then rendered a JSF page that contains some javascript to do a GET request to the pdf-generation servlet (a META refresh tag might also work). The PDF servlet then used the session-scoped data to generate the appropriate PDF document. Regards, Simon Bernd Bohmann schrieb: Hello Andreas, is your action immediate=true ? Regards Bernd Andreas Niemeyer schrieb: yippi :) Thank you all! Regards, Andreas Richard Yee schrieb: Try using divelement.style.display=none Regards, Richard On Wed, Dec 10, 2008 at 6:27 AM, Andreas Niemeyer [EMAIL PROTECTED] wrote: Hi, It works. The only problem is the left space from the invisible div tag. Regards, Andreas div id=error_messages style=color: darkred;visibility: visible t:messages id=error_messages showDetail=true showSummary=false / /div h:commandButton id=reportbutton onclick=clearMessages('error_messages') value=#{msgs.CreateReportButton} action=#{pdfreport.createPDFReport} / JavaScript: function clearMessages(aMessagesID) { var divelement = document.getElementById(aMessagesID); divelement.style.visibility='hidden'; } Andreas Niemeyer schrieb: Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hi, It works. The only problem is the left space from the invisible div tag. Regards, Andreas div id=error_messages style=color: darkred;visibility: visible t:messages id=error_messages showDetail=true showSummary=false / /div h:commandButton id=reportbutton onclick=clearMessages('error_messages') value=#{msgs.CreateReportButton} action=#{pdfreport.createPDFReport} / JavaScript: function clearMessages(aMessagesID) { var divelement = document.getElementById(aMessagesID); divelement.style.visibility='hidden'; } Andreas Niemeyer schrieb: Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Try using divelement.style.display=none Regards, Richard On Wed, Dec 10, 2008 at 6:27 AM, Andreas Niemeyer [EMAIL PROTECTED] wrote: Hi, It works. The only problem is the left space from the invisible div tag. Regards, Andreas div id=error_messages style=color: darkred;visibility: visible t:messages id=error_messages showDetail=true showSummary=false / /div h:commandButton id=reportbutton onclick=clearMessages('error_messages') value=#{msgs.CreateReportButton} action=#{pdfreport.createPDFReport} / JavaScript: function clearMessages(aMessagesID) { var divelement = document.getElementById(aMessagesID); divelement.style.visibility='hidden'; } Andreas Niemeyer schrieb: Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
yippi :) Thank you all! Regards, Andreas Richard Yee schrieb: Try using divelement.style.display=none Regards, Richard On Wed, Dec 10, 2008 at 6:27 AM, Andreas Niemeyer [EMAIL PROTECTED] wrote: Hi, It works. The only problem is the left space from the invisible div tag. Regards, Andreas div id=error_messages style=color: darkred;visibility: visible t:messages id=error_messages showDetail=true showSummary=false / /div h:commandButton id=reportbutton onclick=clearMessages('error_messages') value=#{msgs.CreateReportButton} action=#{pdfreport.createPDFReport} / JavaScript: function clearMessages(aMessagesID) { var divelement = document.getElementById(aMessagesID); divelement.style.visibility='hidden'; } Andreas Niemeyer schrieb: Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Andreas, is your action immediate=true ? Regards Bernd Andreas Niemeyer schrieb: yippi :) Thank you all! Regards, Andreas Richard Yee schrieb: Try using divelement.style.display=none Regards, Richard On Wed, Dec 10, 2008 at 6:27 AM, Andreas Niemeyer [EMAIL PROTECTED] wrote: Hi, It works. The only problem is the left space from the invisible div tag. Regards, Andreas div id=error_messages style=color: darkred;visibility: visible t:messages id=error_messages showDetail=true showSummary=false / /div h:commandButton id=reportbutton onclick=clearMessages('error_messages') value=#{msgs.CreateReportButton} action=#{pdfreport.createPDFReport} / JavaScript: function clearMessages(aMessagesID) { var divelement = document.getElementById(aMessagesID); divelement.style.visibility='hidden'; } Andreas Niemeyer schrieb: Hello Helmut, Good proposal to handle this about JavaScript before send the form. I'll give it a trial. Kind regards, Andreas Helmut Swaczinna schrieb: Hello Andreas, I don't think Tobago or JSF can clear the messages for you. But you can clear the messages on the page yourself with some javascript before the action for the PDF generation gets submitted. For example: ... action=controller.createPDF onclick=clearMessagesAndSubmit('@autoId') ... function clearMessagesAndSubmit(actionId) { // Find messages and clear them Var message = document.getElenemtById('page:message'); message.value = ; Tobago.submitAction(actionId, false); } I haven't tried this, but I think it should work. Regards Helmut - Original Message - From: Andreas Niemeyer [EMAIL PROTECTED] To: users@myfaces.apache.org Sent: Wednesday, December 10, 2008 11:11 AM Subject: Re: JSF servlet request in action method or navigation rule to get binary servlet data? Hello Bernd, Yes, I did. There seems to be no way to get previous messages away due I don't get the page reloaded. I'll open a new thread and try to describe in more detail the requirements. Thank you. Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet ... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet ... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas
Re: JSF servlet request in action method or navigation rule to get binary servlet data?
Hello Andreas, are you calling FacesContext.getCurrentInstance().responseComplete() ? Regards Bernd Andreas Niemeyer schrieb: Hello Bernd, Thank you for response. Unfortunatly I have to use this servlet as a pdf dynamic provider. The redirect works fine so far, but another thing happened. Due some validation rules in the same method, a previous custom FacesMessage stays displayed and only after a page reload it goes away. Have someone an idea? Regards, Andreas Bernd Bohmann schrieb: Hello Andreas, maybe this help: http://wiki.apache.org/myfaces/Sending_Files You don't need a Servlet for sending binary data from jsf. The magic is the responseComplete() method. Please look at the Section 2.1.3 Faces Request Generates Non-Faces Response of the jsf 1.1 spec. Regards Bernd Andreas Niemeyer schrieb: Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas
JSF servlet request in action method or navigation rule to get binary servlet data?
Hi, I would like to send form data from a JSF page for a servlet request with a navigation rule. The servlet returns a content type of application/pdf and is running in a context path. If I call it from within a action method, it works with following code: public String createPDFReport() { ... FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ext = context.getExternalContext(); String vServletPath = /context_path/pdf-test; ext.redirect(ext.encodeResourceURL(vServletPath)); ... return call_servlet; } My context is a portal, I'm using the JSF portal bridge. The web.xml looks like: ... servlet servlet-namepdf-test/servlet-name servlet-classcom.xxx.PDFTest/servlet-class load-on-startup20/load-on-startup /servlet ... I would like to avoid to send a redirect and would prefer to create a navigation rule in the faces-config, but it fails with an exception arised from my GenericPortlet ... public class JSFGenericPortlet extends org.apache.myfaces.portlet.MyFacesGenericPortlet { ... public void render(RenderRequest req, RenderResponse res) throws IOException, PortletException { ... super.render(req, res); } ... } javax.portlet.PortletException: String index out of range: -1 at org.apache.myfaces.portlet.MyFacesGenericPortlet.handleExceptionFromLifecycle(MyFacesGenericPortlet.java:310) at org.apache.myfaces.portlet.MyFacesGenericPortlet.facesRender(MyFacesGenericPortlet.java:502) at org.apache.myfaces.portlet.MyFacesGenericPortlet.doView(MyFacesGenericPortlet.java:323) at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328) at javax.portlet.GenericPortlet.render(GenericPortlet.java:233) at com.gutzmann.portlets.JSFGenericPortlet.render(JSFGenericPortlet.java:73) The navigation rule looks like: navigation-rule from-view-id/pages/view.xhtml/from-view-id navigation-case from-outcomecall_servlet/from-outcome to-view-id/pdf-test//to-view-id /navigation-case /navigation-rule I tried also `to-view-id/context_path/pdf-test//to-view-id' - same exception. What is the best practice to do such redirect / servlet calls? If request parameter should be changed, how would it work in the action method? Many thanks fro some help! Regards, Andreas