You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Thomas Gaudin <th...@gmail.com> on 2006/04/04 14:08:32 UTC

Problem when report generation and JSF navigation

Hi,

I am using JasperReport to generate PDF files "on the fly".
It is working fine the first time I click on the link to the report but it
fails alternatively every 2 clicks exactly...
I guess I am somehow messing up the navigation mecanism but I don't know
where to start my investigation.
Any hint is warmly welcome.
Thanks,

Thomas

Here is the code :
--------------------
JSF Bean :
public class Reports extends BasePage implements Serializable {
    public String users() {
        List results = userManager.getUsers(null);
        Map parameters = new HashMap();
        parameters.put("format", "pdf");
        parameters.put("WEBDIR", getServletContext().getRealPath("/"));
        try{
            InputStream is =
getServletContext().getResourceAsStream("/WEB-INF/reports/userList.jrxml");
            JRBeanCollectionDataSource ds = new
JRBeanCollectionDataSource(results);

            getResponse().setContentType("application/pdf");
            getResponse().addHeader("Content-Disposition", "attachment;
filename=userList.pdf");

            JasperDesign jasperDesign = JRXmlLoader.load(is);
            JasperReport jasperReport = JasperCompileManager.compileReport
(jasperDesign);
            JasperPrint jasperPrint =
JasperFillManager.fillReport(jasperReport,
parameters, ds);
            JasperExportManager.exportReportToPdfStream(jasperPrint,
getResponse().getOutputStream());

            getFacesContext().responseComplete();
        }
        catch(Exception e){
            log.error(e);
        }
        return null;
    }
--------------------
The link to generate report :
<h:commandLink value="report" action="#{reports.users}"/>
--------------------
faces-config.xml :
     <managed-bean>
        <managed-bean-name>reports</managed-bean-name>
        <managed-bean-class>org.appfuse.webapp.action.Reports
</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>userManager</property-name>
            <value>#{userManager}</value>
        </managed-property>
    </managed-bean>
--------------------

Re: Problem when report generation and JSF navigation

Posted by Thomas Gaudin <th...@gmail.com>.
Works like a charm!
Thanks Murat (and Martin)

Thomas

On 4/4/06, Murat Hazer <mu...@gmail.com> wrote:
>
> Hi,
>
> You should add this line just above facesContext.responseComplete() line;
>
> facesContext.getApplication().getStateManager().saveSerializedView(
>             facesContext);
>
> PS: Martin's solution...
>
>
> On 4/4/06, Sébastien Marin <th...@free.fr> wrote:
> >
> > Hello, i have the same problem. The first action is Ok but the second
> > just do a
> > refresh or made error. It is the same process when we click on the back
> > icon of
> > the web browser.
> >
> > I would like to understand. Thanks
> > Selon Thomas Gaudin <th...@gmail.com>:
> >
> > -> Hi,
> > ->
> > -> I am using JasperReport to generate PDF files "on the fly".
> > -> It is working fine the first time I click on the link to the report
> > but it
> > -> fails alternatively every 2 clicks exactly...
> > -> I guess I am somehow messing up the navigation mecanism but I don't
> > know
> > -> where to start my investigation.
> > -> Any hint is warmly welcome.
> > -> Thanks,
> > ->
> > -> Thomas
> > ->
> > -> Here is the code :
> > -> --------------------
> > -> JSF Bean :
> > -> public class Reports extends BasePage implements Serializable {
> > ->     public String users() {
> > ->         List results = userManager.getUsers(null);
> > ->         Map parameters = new HashMap();
> > ->         parameters.put("format", "pdf");
> > ->         parameters.put("WEBDIR",
> > getServletContext().getRealPath("/"));
> > ->         try{
> > ->             InputStream is =
> > ->
> > getServletContext().getResourceAsStream("/WEB-INF/reports/userList.jrxml");
> > ->             JRBeanCollectionDataSource ds = new
> > -> JRBeanCollectionDataSource(results);
> > ->
> > ->             getResponse().setContentType("application/pdf");
> > ->             getResponse().addHeader("Content-Disposition",
> > "attachment;
> > -> filename=userList.pdf");
> > ->
> > ->             JasperDesign jasperDesign = JRXmlLoader.load(is);
> > ->             JasperReport jasperReport =
> > JasperCompileManager.compileReport
> > -> (jasperDesign);
> > ->             JasperPrint jasperPrint =
> > -> JasperFillManager.fillReport(jasperReport,
> > -> parameters, ds);
> > ->             JasperExportManager.exportReportToPdfStream(jasperPrint,
> > -> getResponse().getOutputStream());
> > ->
> > ->             getFacesContext().responseComplete();
> > ->         }
> > ->         catch(Exception e){
> > ->             log.error(e);
> > ->         }
> > ->         return null;
> > ->     }
> > -> --------------------
> > -> The link to generate report :
> > -> <h:commandLink value="report" action="#{reports.users}"/>
> > -> --------------------
> > -> faces-config.xml :
> > ->      <managed-bean>
> > ->         <managed-bean-name>reports</managed-bean-name>
> > ->         <managed-bean-class>org.appfuse.webapp.action.Reports
> > -> </managed-bean-class>
> > ->         <managed-bean-scope>request</managed-bean-scope>
> > ->         <managed-property>
> > ->             <property-name>userManager</property-name>
> > ->             <value>#{userManager}</value>
> > ->         </managed-property>
> > ->     </managed-bean>
> >
>
>
>
> --
> Murat HAZER
> Elektrik-Elektronik Mühendisi - Electrical-Electronics Engineer
> Tel - Phone: +90 222 335 05 80 - 1395
> Cep Tel - Mobile Phone: +90 532 472 00 63
> Blog URL: http://www.projedunyasi.org
> Yahoo Group: http://groups.yahoo.com/group/malatyafenlisesi/
>

Re: Problem when report generation and JSF navigation

Posted by Murat Hazer <mu...@gmail.com>.
Hi,

You should add this line just above facesContext.responseComplete() line;

facesContext.getApplication().getStateManager().saveSerializedView(
        facesContext);

PS: Martin's solution...

On 4/4/06, Sébastien Marin <th...@free.fr> wrote:
>
> Hello, i have the same problem. The first action is Ok but the second just
> do a
> refresh or made error. It is the same process when we click on the back
> icon of
> the web browser.
>
> I would like to understand. Thanks
> Selon Thomas Gaudin <th...@gmail.com>:
>
> -> Hi,
> ->
> -> I am using JasperReport to generate PDF files "on the fly".
> -> It is working fine the first time I click on the link to the report but
> it
> -> fails alternatively every 2 clicks exactly...
> -> I guess I am somehow messing up the navigation mecanism but I don't
> know
> -> where to start my investigation.
> -> Any hint is warmly welcome.
> -> Thanks,
> ->
> -> Thomas
> ->
> -> Here is the code :
> -> --------------------
> -> JSF Bean :
> -> public class Reports extends BasePage implements Serializable {
> ->     public String users() {
> ->         List results = userManager.getUsers(null);
> ->         Map parameters = new HashMap();
> ->         parameters.put("format", "pdf");
> ->         parameters.put("WEBDIR", getServletContext().getRealPath("/"));
> ->         try{
> ->             InputStream is =
> ->
> getServletContext().getResourceAsStream("/WEB-INF/reports/userList.jrxml");
> ->             JRBeanCollectionDataSource ds = new
> -> JRBeanCollectionDataSource(results);
> ->
> ->             getResponse().setContentType("application/pdf");
> ->             getResponse().addHeader("Content-Disposition", "attachment;
> -> filename=userList.pdf");
> ->
> ->             JasperDesign jasperDesign = JRXmlLoader.load(is);
> ->             JasperReport jasperReport =
> JasperCompileManager.compileReport
> -> (jasperDesign);
> ->             JasperPrint jasperPrint =
> -> JasperFillManager.fillReport(jasperReport,
> -> parameters, ds);
> ->             JasperExportManager.exportReportToPdfStream(jasperPrint,
> -> getResponse().getOutputStream());
> ->
> ->             getFacesContext().responseComplete();
> ->         }
> ->         catch(Exception e){
> ->             log.error(e);
> ->         }
> ->         return null;
> ->     }
> -> --------------------
> -> The link to generate report :
> -> <h:commandLink value="report" action="#{reports.users}"/>
> -> --------------------
> -> faces-config.xml :
> ->      <managed-bean>
> ->         <managed-bean-name>reports</managed-bean-name>
> ->         <managed-bean-class>org.appfuse.webapp.action.Reports
> -> </managed-bean-class>
> ->         <managed-bean-scope>request</managed-bean-scope>
> ->         <managed-property>
> ->             <property-name>userManager</property-name>
> ->             <value>#{userManager}</value>
> ->         </managed-property>
> ->     </managed-bean>
>



--
Murat HAZER
Elektrik-Elektronik Mühendisi - Electrical-Electronics Engineer
Tel - Phone: +90 222 335 05 80 - 1395
Cep Tel - Mobile Phone: +90 532 472 00 63
Blog URL: http://www.projedunyasi.org
Yahoo Group: http://groups.yahoo.com/group/malatyafenlisesi/

Re: Problem when report generation and JSF navigation

Posted by Sébastien Marin <th...@free.fr>.
Hello, i have the same problem. The first action is Ok but the second just do a
refresh or made error. It is the same process when we click on the back icon of
the web browser.

I would like to understand. Thanks
Selon Thomas Gaudin <th...@gmail.com>:

-> Hi,
->
-> I am using JasperReport to generate PDF files "on the fly".
-> It is working fine the first time I click on the link to the report but it
-> fails alternatively every 2 clicks exactly...
-> I guess I am somehow messing up the navigation mecanism but I don't know
-> where to start my investigation.
-> Any hint is warmly welcome.
-> Thanks,
->
-> Thomas
->
-> Here is the code :
-> --------------------
-> JSF Bean :
-> public class Reports extends BasePage implements Serializable {
->     public String users() {
->         List results = userManager.getUsers(null);
->         Map parameters = new HashMap();
->         parameters.put("format", "pdf");
->         parameters.put("WEBDIR", getServletContext().getRealPath("/"));
->         try{
->             InputStream is =
-> getServletContext().getResourceAsStream("/WEB-INF/reports/userList.jrxml");
->             JRBeanCollectionDataSource ds = new
-> JRBeanCollectionDataSource(results);
->
->             getResponse().setContentType("application/pdf");
->             getResponse().addHeader("Content-Disposition", "attachment;
-> filename=userList.pdf");
->
->             JasperDesign jasperDesign = JRXmlLoader.load(is);
->             JasperReport jasperReport = JasperCompileManager.compileReport
-> (jasperDesign);
->             JasperPrint jasperPrint =
-> JasperFillManager.fillReport(jasperReport,
-> parameters, ds);
->             JasperExportManager.exportReportToPdfStream(jasperPrint,
-> getResponse().getOutputStream());
->
->             getFacesContext().responseComplete();
->         }
->         catch(Exception e){
->             log.error(e);
->         }
->         return null;
->     }
-> --------------------
-> The link to generate report :
-> <h:commandLink value="report" action="#{reports.users}"/>
-> --------------------
-> faces-config.xml :
->      <managed-bean>
->         <managed-bean-name>reports</managed-bean-name>
->         <managed-bean-class>org.appfuse.webapp.action.Reports
-> </managed-bean-class>
->         <managed-bean-scope>request</managed-bean-scope>
->         <managed-property>
->             <property-name>userManager</property-name>
->             <value>#{userManager}</value>
->         </managed-property>
->     </managed-bean>