Have a look at RequestCycle#setRequestTarget.

Additionnaly, you may have a look at SubmitLink, since the validation step has nothing to do in the onClick of a link

jeredm wrote:
I am using FOP to create a PDF dynamically based on user input into a web
form. I don't have a problem creating the PDF only with the display of it. I need that PDF to be immediately sent to the user via a redirect or
download.  so something like this ....

@Override
public void onClick(){
  validateUserDataFromForm();

  if(!hasErrorMessage()){
     ByteArrayOutputStream pdfData =
factory.createPDF(startDateThatIsSetViaTheForm, endDateThatIsSetViaTheForm,
reportType);

     // Output the steam to a page I can redirect to.
     // I can use a File if ByteArrayOutputStream is making things tough.
     // I am fine if the user gets prompted like a download link, but I want
a single click to create and prompt for download.
  }
}


.... Here is what I have tried.
1) Making the PDF a resource:  This worked initially as I needed it to, but
I was having problems with the resource being reused and while the report
needed to vary on each generation.  Basically, I need to create the PDF,
give it to the user, and then destroy the copy on the server.  Every time
the user clicks the create button a new PDF needs to be built and sent to
the user.  I also don't like this option as I don't want to waste memory by
adding too many resources that are not re-used.  I need the user data to
update the display of the PDF when it is built, so I need the link to pass
in new values to the createPDF function every time.

2) Something like this...
final Response response = getRequestCycle().getResponse();
response.setContentType("application/pdf");
response.setContentLength(pdfout.size());
                                        
try{
  OutputStream stream = response.getOutputStream();
  stream.write(pdfData.toByteArray());
  stream.flush();
}catch(Exception ex){
  throw new RuntimeException(ex);
}

That results in an error like so...
[org.apache.wicket.protocol.http.WicketFilter] - closing the buffer error...

Any help would be appreciated!  Thanks!

Jered



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to