You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2013/04/24 18:11:49 UTC

Firing ajax request while returning a StreamResponse

So I'm facing a dilemma where my app uses hibernate version to prevent
optimistic locking, but returns a PDF from a StreamResponse. When the user
uses the submit action to generate a PDF, a few items are first saved to
the database from a web service which causes the version to increment
followed by the PDF being returned as a StreamResponse in my onSuccess
method. The problem I'm having is the hidden field within the form
containing the previous version isn't being updated do to the fact the
StreamResponse doesn't reload the page. This causes the form to fall out of
sync with the database causing a serverside validation error.

My question is whether or not there is away to update form data with a Zone
while the StreamResponse is being returned? I'm open to alternate
suggestions as well.

Re: Firing ajax request while returning a StreamResponse

Posted by George Christman <gc...@cardaddy.com>.
Ah yes, I didn't even give flash persist a thought, I think I'd rather use
that to minimize url tampering. Thanks Lance.


On Wed, Apr 24, 2013 at 1:53 PM, Lance Java <la...@googlemail.com>wrote:

> Something like this (not tested)
>
> @Inject
> private ComponentResources resources;
>
> @Inject
> private JavaScriptSupport jss;
>
> @Persist(PersistanceConstants.FLASH)
> private String pdfUrl;
>
> @SetupRender
> void setupRender() {
> if (pdfUrl != null) {
> jss.addScript("document.location.href = '%s';", pdfUrl);
> }
> }
>
> void onSuccessFromForm() {
> long pdfId = doWorkPriorToPdfGeneration(...);
> pdfUrl = resources.createEventLink("generatePdf", pdfId);
> }
>
> StreamResponse generatePdf(long pdfId) {
> // generate the PDF
> }
>
> If you don't want to use flash persistence, you can use page activation
> context or a request parameter etc.
>
>
> On 24 April 2013 17:51, George Christman <gc...@cardaddy.com> wrote:
>
> > Hi Lance, I think I'm with you most of the way with the exception of
> > generating a link to the pdf event.
> >
> > So I'm returning PurchaseRequest.class in my onSuccess method which would
> > for the page to reload with context from onPassivate, this should resolve
> > my sync issues. Where I'm lost is how to trigger the script to call the
> > StreamResponse. I thought maybe this could be done in the url like so,
> > http://domain/purchaserequest/958:generatepdf. I'm just not sure what
> the
> > appropriate way of doing this is, or how to do it at that. I'm assuming
> you
> > would need some sort of business logic to prevent people from just using
> > that same URL over and over again. How would you tigger the script on
> > return?
> >
> > Thanks Lance.
> >
> >
> > On Wed, Apr 24, 2013 at 12:37 PM, Lance Java <lance.java@googlemail.com
> > >wrote:
> >
> > > Split it into 2 phases:
> > >
> > > Phase 1: Submit form
> > > Do the work (webservice + version increment)
> > > Generate a link to the generatePDF event
> > > Return the page to be re-rendered
> > >
> > > Phase 2: Re-render the page
> > > Use javascript to download the PDF once the page has loaded.
> > >
> >
>



-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Firing ajax request while returning a StreamResponse

Posted by Lance Java <la...@googlemail.com>.
Something like this (not tested)

@Inject
private ComponentResources resources;

@Inject
private JavaScriptSupport jss;

@Persist(PersistanceConstants.FLASH)
private String pdfUrl;

@SetupRender
void setupRender() {
if (pdfUrl != null) {
jss.addScript("document.location.href = '%s';", pdfUrl);
}
}

void onSuccessFromForm() {
long pdfId = doWorkPriorToPdfGeneration(...);
pdfUrl = resources.createEventLink("generatePdf", pdfId);
}

StreamResponse generatePdf(long pdfId) {
// generate the PDF
}

If you don't want to use flash persistence, you can use page activation
context or a request parameter etc.


On 24 April 2013 17:51, George Christman <gc...@cardaddy.com> wrote:

> Hi Lance, I think I'm with you most of the way with the exception of
> generating a link to the pdf event.
>
> So I'm returning PurchaseRequest.class in my onSuccess method which would
> for the page to reload with context from onPassivate, this should resolve
> my sync issues. Where I'm lost is how to trigger the script to call the
> StreamResponse. I thought maybe this could be done in the url like so,
> http://domain/purchaserequest/958:generatepdf. I'm just not sure what the
> appropriate way of doing this is, or how to do it at that. I'm assuming you
> would need some sort of business logic to prevent people from just using
> that same URL over and over again. How would you tigger the script on
> return?
>
> Thanks Lance.
>
>
> On Wed, Apr 24, 2013 at 12:37 PM, Lance Java <lance.java@googlemail.com
> >wrote:
>
> > Split it into 2 phases:
> >
> > Phase 1: Submit form
> > Do the work (webservice + version increment)
> > Generate a link to the generatePDF event
> > Return the page to be re-rendered
> >
> > Phase 2: Re-render the page
> > Use javascript to download the PDF once the page has loaded.
> >
>

Re: Firing ajax request while returning a StreamResponse

Posted by George Christman <gc...@cardaddy.com>.
Hi Lance, I think I'm with you most of the way with the exception of
generating a link to the pdf event.

So I'm returning PurchaseRequest.class in my onSuccess method which would
for the page to reload with context from onPassivate, this should resolve
my sync issues. Where I'm lost is how to trigger the script to call the
StreamResponse. I thought maybe this could be done in the url like so,
http://domain/purchaserequest/958:generatepdf. I'm just not sure what the
appropriate way of doing this is, or how to do it at that. I'm assuming you
would need some sort of business logic to prevent people from just using
that same URL over and over again. How would you tigger the script on
return?

Thanks Lance.


On Wed, Apr 24, 2013 at 12:37 PM, Lance Java <la...@googlemail.com>wrote:

> Split it into 2 phases:
>
> Phase 1: Submit form
> Do the work (webservice + version increment)
> Generate a link to the generatePDF event
> Return the page to be re-rendered
>
> Phase 2: Re-render the page
> Use javascript to download the PDF once the page has loaded.
>

Re: Firing ajax request while returning a StreamResponse

Posted by Lance Java <la...@googlemail.com>.
Split it into 2 phases:

Phase 1: Submit form
Do the work (webservice + version increment)
Generate a link to the generatePDF event
Return the page to be re-rendered

Phase 2: Re-render the page
Use javascript to download the PDF once the page has loaded.