You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Robert Cole <ro...@db.com> on 2005/09/27 15:45:28 UTC

Page recorder for page X locked after a commit()

Hi All,

Tapestry 3.0.3 on JDK 1.5

I'm running into the locked page problem when trying to read the content of multiple pages to generate a PDF.

Some background. We've written a page that is used to display company information for 200 companies. The pages a normally viewed as HTML, but I've written some code that uses the IRequestCycle to render the page that I capture and convert to a PDF, which all works fine.

The problem is that now we need to convert all of the company pages to 1 big PDF rather than 200 small ones. I don't want to write a page that shows every company page as an HTML page and then convert that as it would use a large amount of memory and CPU. So, I'm trying to convert each page at a time and then get the 1st page of the PDF and add that to a larger document.

So, the process goes:
   Service receives request.
   Gets list of companies
   For each company:
      Generate the HTML page
      Convert to PDF
      Add pdf page to big report

The problem is that the second time I try to activate the company page I get the error shown below:

org.apache.tapestry.ApplicationRuntimeException
Page recorder for page Issuer is locked after a commit(), but received a change to property issuerTicker of component Issuer.

The code that activates the page is below. The "cycle" object is the instance of IRequestCycle that is represents the request, so its the one that's passed into the service that is doing all of the work, so the same cycle is used each time I use the underlying page to generate the HTML (see where this is going?)

        IPage page = cycle.getPage(pageName);
        cycle.setServiceParameters(parameters);
        cycle.activate(page);

        if (page instanceof IExternalPage) {
            IExternalPage externalPage = (IExternalPage) page;
            externalPage.activateExternalPage(parameters, cycle);
        }

        byte[] response = renderAndCaptureResponse(cycle);

The last method is:

    private byte[] renderAndCaptureResponse(IRequestCycle cycle) {

        ByteArrayOutputStream output = new ByteArrayOutputStream(2046);
        IPage page = cycle.getPage();
        IMarkupWriter writer = page.getResponseWriter(output);
        try {
            cycle.renderPage(writer);
        } finally {
            writer.close();
        }

        return output.toByteArray();
    }

Having looked at the documentation around the page recorder I can see that the commit() method locks the PageRecorder until the next request cycle. So, when I come to use the page with a new set of parameters, the page falls over with the exception since I'm using the same cycle each time.

The question is, how do I get around it, or stop it happening? Can I create a new IRequestCycle object, or clone the existing one so that each page is rendered for a different request cycle? Or can I tell the page recorder to uncommit the commit?

Thanks,

Rob Cole
CSA Web



--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



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


Re: Page recorder for page X locked after a commit()

Posted by Kent Tong <ke...@cpttm.org.mo>.
Robert Cole <robert.cole <at> db.com> writes:

> I've tried the change, and it looks like I've substituted the error for 
> another one. I'm now getting an ApplicationRuntimeException stating "Body 
> components may not be nested". Again, this is happening
> when I call the second page. Stacktrace below:

I think the best solution is to put the part of the page displaying
a company's info into a say CompanyInfo component. Then to show all 
the companies in one page, just create a regular tapestry page like:

<span jwcid="@For" ...>
  <span jwcid="@CompanyInfo" .../>
</span>

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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


Re: Page recorder for page X locked after a commit()

Posted by Robert Cole <ro...@db.com>.
Hi Kent,

Thanks for taking the time to help me.

I've tried the change, and it looks like I've substituted the error for another one. I'm now getting an ApplicationRuntimeException stating "Body components may not be nested". Again, this is happening when I call the second page. Stacktrace below:

Stack Trace:
org.apache.tapestry.html.Body.renderComponent(Body.java:257)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
org.apache.tapestry.html.Shell.renderComponent(Shell.java:124)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
com.db.csa.tapestry.core.CSABaseComponent.renderComponent(CSABaseComponent.java:90)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
com.db.csa.tapestry.service.pdf.PDFProducer.renderAndCaptureResponse(PDFProducer.java:92)
com.db.csa.tapestry.service.pdf.PDFProducer.create(PDFProducer.java:66)
com.db.csa.tapestry.service.pdf.AllIssuersTearsheetsService.generateDocument(AllIssuersTearsheetsService.java:82)
com.db.csa.tapestry.service.pdf.AllIssuersTearsheetsService.service(AllIssuersTearsheetsService.java:54)
org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:889)
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:198)
org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:159)
javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:413)
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:748)
org.apache.tapestry.RedirectFilter.doFilter(RedirectFilter.java:106)
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:739)
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:527)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:569)
org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:624)
org.mortbay.http.HttpContext.handle(HttpContext.java:1434)
org.mortbay.http.HttpServer.service(HttpServer.java:896)
org.mortbay.http.HttpConnection.service(HttpConnection.java:814)
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:981)
org.mortbay.http.HttpConnection.handle(HttpConnection.java:831)
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:244)
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:366)
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)


Rob Cole
CSA Web




                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
             Kent Tong <ke...@cpttm.org.mo>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
             Sent by: news <ne...@sea.gmane.org>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           To 
                                                                                                                                                                                                                                                                                                                                                                                                                        tapestry-user@jakarta.apache.org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
             28/09/2005 17:39                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              cc 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Subject 
                                                                                                                                                                                                     Please respond to                                                                                                                                                                                                  Re: Page recorder for page X locked after a commit()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                    "Tapestry users" <ta...@jakarta.apache.org>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              




Robert Cole <robert.cole <at> db.com> writes:

>     private byte[] renderAndCaptureResponse(IRequestCycle cycle) {
>
>         ByteArrayOutputStream output = new ByteArrayOutputStream(2046);
>         IPage page = cycle.getPage();
>         IMarkupWriter writer = page.getResponseWriter(output);
>         try {
>             cycle.renderPage(writer);
>         } finally {
>             writer.close();
>         }
>         return output.toByteArray();
>     }

No sure if it will work, but you may try:

     private byte[] renderAndCaptureResponse(IRequestCycle cycle) {
         ByteArrayOutputStream output = new ByteArrayOutputStream(2046);
         IPage page = cycle.getPage();
         IMarkupWriter writer = page.getResponseWriter(output);
         try {
             page.render(writer, cycle);
         } finally {
             writer.close();
         }
         return output.toByteArray();
     }

However, this way the pageBeginRender listeners (if any) won't be called.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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






--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



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


Re: Page recorder for page X locked after a commit()

Posted by Kent Tong <ke...@cpttm.org.mo>.
Robert Cole <robert.cole <at> db.com> writes:

>     private byte[] renderAndCaptureResponse(IRequestCycle cycle) {
> 
>         ByteArrayOutputStream output = new ByteArrayOutputStream(2046);
>         IPage page = cycle.getPage();
>         IMarkupWriter writer = page.getResponseWriter(output);
>         try {
>             cycle.renderPage(writer);
>         } finally {
>             writer.close();
>         }
>         return output.toByteArray();
>     }

No sure if it will work, but you may try:

     private byte[] renderAndCaptureResponse(IRequestCycle cycle) {
         ByteArrayOutputStream output = new ByteArrayOutputStream(2046);
         IPage page = cycle.getPage();
         IMarkupWriter writer = page.getResponseWriter(output);
         try {
             page.render(writer, cycle);
         } finally {
             writer.close();
         }
         return output.toByteArray();
     }

However, this way the pageBeginRender listeners (if any) won't be called.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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


Re: Page recorder for page X locked after a commit()

Posted by Robert Cole <ro...@db.com>.
I take it by the deafening silence that this is either exceptionally trivial or exceptionally hard. Has anyone got any ideas?

Thanks,

Rob Cole
CSA Web




                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
             "Robert Cole" <ro...@db.com>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
             27/09/2005 14:45                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              To 
                                                                                                                                                                                                                                                                                                                                                                                                                        tapestry-user@jakarta.apache.org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           cc 
                                                                                                                                                                                                     Please respond to                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                    "Tapestry users" <ta...@jakarta.apache.org>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Subject 
                                                                                                                                                                                                                                                                                                                                                                                                                        Page recorder for page X locked after a commit()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              




Hi All,

Tapestry 3.0.3 on JDK 1.5

I'm running into the locked page problem when trying to read the content of multiple pages to generate a PDF.

Some background. We've written a page that is used to display company information for 200 companies. The pages a normally viewed as HTML, but I've written some code that uses the IRequestCycle to render the page that I capture and convert to a PDF, which all works fine.

The problem is that now we need to convert all of the company pages to 1 big PDF rather than 200 small ones. I don't want to write a page that shows every company page as an HTML page and then convert that as it would use a large amount of memory and CPU. So, I'm trying to convert each page at a time and then get the 1st page of the PDF and add that to a larger document.

So, the process goes:
   Service receives request.
   Gets list of companies
   For each company:
      Generate the HTML page
      Convert to PDF
      Add pdf page to big report

The problem is that the second time I try to activate the company page I get the error shown below:

org.apache.tapestry.ApplicationRuntimeException
Page recorder for page Issuer is locked after a commit(), but received a change to property issuerTicker of component Issuer.

The code that activates the page is below. The "cycle" object is the instance of IRequestCycle that is represents the request, so its the one that's passed into the service that is doing all of the work, so the same cycle is used each time I use the underlying page to generate the HTML (see where this is going?)

        IPage page = cycle.getPage(pageName);
        cycle.setServiceParameters(parameters);
        cycle.activate(page);

        if (page instanceof IExternalPage) {
            IExternalPage externalPage = (IExternalPage) page;
            externalPage.activateExternalPage(parameters, cycle);
        }

        byte[] response = renderAndCaptureResponse(cycle);

The last method is:

    private byte[] renderAndCaptureResponse(IRequestCycle cycle) {

        ByteArrayOutputStream output = new ByteArrayOutputStream(2046);
        IPage page = cycle.getPage();
        IMarkupWriter writer = page.getResponseWriter(output);
        try {
            cycle.renderPage(writer);
        } finally {
            writer.close();
        }

        return output.toByteArray();
    }

Having looked at the documentation around the page recorder I can see that the commit() method locks the PageRecorder until the next request cycle. So, when I come to use the page with a new set of parameters, the page falls over with the exception since I'm using the same cycle each time.

The question is, how do I get around it, or stop it happening? Can I create a new IRequestCycle object, or clone the existing one so that each page is rendered for a different request cycle? Or can I tell the page recorder to uncommit the commit?

Thanks,

Rob Cole
CSA Web



--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



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






--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



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