Would like to reuse a page event handler function to render that specific 
response on server as a file.  


Generally, how does one make an service wrapper to tapestry pages?  


Specifically, how can tapestry application context be injected in stand-alone 
java program? 


Use-Case:


There is a PDF button on my page that renders the content at request time as a 
file download.  I would like to periodically create that file on the 
server instead.  The catch: would like to use the exact same process, 
not have to write any duplicate code.  In other words, should a user 
happen to download the pdf by clicking the button at exactly the same 
time as the cron job created the file on the server, the two files would be 
identical.  


I have a submit button on a page that renders PDF.  Works fine.  Basically, 
there is a button on the form in the page 

<t:submit t:id="pdf" name="Run Report" value="PDF" /> 


Within the page class I have an onSelectedFromPdf handler that returns 
PDFStreamResponse 
(http://wiki.apache.org/tapestry/Tapestry5HowToCreateADynamicPDF)


I would like to reuse the exact same onSelectFromPdf page handler from 
the command line instead,  streaming the response to a file.  I tried 
injecting the page into services, works (compiles) just fine.  But get 
null response when calling onSelect function - obviously not getting any 
tapestry management, (application context). 

<code>
public class PDFLogger
{

@Inject 
private Page page;  // THIS DOES NOT WORK (NULL)

public PDFStreamResponse getLogs()
{
  return page.onSelectedFromPdf();  // null pointer exception 
}
     
    public static void main(String [] args)
    {

        
//////////////////////////////////////////////////////////////////////////////
        //  this is the problem/question.....................

        PDFLoggger logger = new PDFLogger(); // how to instantiate page 
correctly...in application context etc???????

        PDFStreamResponse response = (PDFStreamResponse) logger.getLogs();
        try
        {
            IOUtils.copy(response.getStream(), System.out);    
        }
        catch (IOException ioe) 
        {
            throw new RuntimeException("error reading stream", ioe);
        } 
    }

</code>


Hope this is useful to someone with same type of question.  Thanks in advance 
to the experts...

Reply via email to