Thank you Ernesto.
I've found a different solution.
Need 2 pages: NoPdfPage and MyPdfPage.
1). When hyperlink for PDF is clicked, onclick event opens a new window, which
points to PDF url, e.g. /myapp/MyPdf.go?params_go_here (Extension doesn't
matter. Iframes also work, just supply iframe id as a target to hyperlink or
form);
2). Create NoPdf page.
3). MyPdf.go maps to MyPdfPage.java
/**
*
*/
package ...;
public class MyPdfPage extends WebPage
{
public MyPdfPage(PageParameters parameters) {
super(parameters);
String url = "generate_url_to_pdf_file";
if(!readPdf(url)) {
//Redirect to No Pdf page.
this.setResponsePage(NoPdfPage.class);
}
}
private boolean readPdf(String stmtUrl) throws Exception {
final HttpServletResponse response =
getWebRequestCycle().getWebResponse().getHttpServletResponse();
BufferedInputStream in = null;
OutputStream out = null;
try {
//pdf file may locate either on the same or other box.
URL url = new URL(stmtUrl);
URLConnection con = url.openConnection();
in = new BufferedInputStream(con.getInputStream());
//Get here if file exists
response.setContentType("application/pdf");
out = response.getOutputStream();
in = new BufferedInputStream(con.getInputStream());
int i = 0;
byte[] bytesIn = new byte[1024];
while ((i = in.read(bytesIn)) >= 0) {
out.write(bytesIn, 0, i);
}
return true;
} catch (FileNotFoundException ex) {
String errMsg = "File not exists: " + stmtUrl;
logger.info(errMsg);
return false;
} catch (Exception ex) {
String errMsg = "Error processing file: " + stmtUrl;
throw ex;
} finally {
if (in != null) {
try{in.close();}catch(Exception e) {}
}
if (out != null) {
try{out.close();}catch(Exception e) {}
}
}
}
/* (non-Javadoc)
* @see wicket.Page#onRender(wicket.markup.MarkupStream)
*/
protected void onRender(MarkupStream markupStream)
{
}
/* (non-Javadoc)
* @see wicket.markup.html.WebPage#configureResponse()
*/
protected void configureResponse()
{
}
}
Works fine without .pdf extension and response.setHeader("Content-Disposition",
"inline;
filename=\"" + name + "\"");
----------------------------------------------------
Eugene
This e-mail and any attachments may contain confidential information. Any
distributing, copying or reliance upon the contents of this e-mail by anyone
other
than the intended recipient is strictly prohibited. If you have received this
e-mail
accidentally, please delete it and notify the sender. Although this message has
been
screened for viruses, we cannot guarantee that our virus scanner will detect
all
viruses and take no responsibility for any damage or loss that may be caused by
its
contents.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user