Very simple scenario , I wanted to display a PDF or an Excel on click of a link/ on submit of a button.
Since wicket offers flavors of ajaxbutton and ajax link one can easily make a mistake of the using them to render the pdf or excel.
I did the same. everything seemed to work unit the point where the response needed to be rendered and i would see a pdf or excel.
The problem was that using an ajax button or link we can only render a ajax response, but in this case i wanted to render a pdf or excel response (bytes).
It only clicked to me after a while of debugging that the browser had no way to identify how to render the ajax response which contained pdf bytes.
Lesson learnt , always use a Normal Button or a link to render the pdf as the web response.
an example would be like this:
Link excelLink = new Link("linForExcel"){
@Override
public void onClick() {
final OutputStream excelOutputStream = methodToReturnTheExcelOutputStream();
final ByteArrayResource byteArrayResource = new ByteArrayResource("application/vnd.ms-excel", ((ByteArrayOutputStream) excelOutputStream).toByteArray());
IResourceStream resourceStream = byteArrayResource.getResourceStream();
getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream) {
public String getFileName() {
return "NameOfExcel.csv";
}
});
}
I guess this is a page to share all issues I have troubleshooted and found interesting enough to share. Also a place to give back something , in return of all the help I have received or taken from forums.
Showing posts with label excel. Show all posts
Showing posts with label excel. Show all posts
Friday, 9 July 2010
Wicket - Displaying a PDF onclick of a link or onSubmit of a Button
Monday, 18 May 2009
SQL Server PIVOT - Magic isn't it
Ever wonders how you could present data via a select statement horizontally instead of vertically. When your columns come from the data you are retrieving from the select statement. The answer is simple in TSQL called the pivot keyword. All it would do is to use the data as the pivot to form the columns. Consider the simple schema of the employee: Product
- Name
- ID
- ID
- Agent ID
- Quantity
- Name
- ID
PIVOT (SUM(Quantity) for Agent IN (Agent1, Agent2, Agent3)) AS pvt
Labels:
excel,
horizontal result set,
pivot,
sql server
Subscribe to:
Comments (Atom)