>From 2006/02/01:  

Me: 
>> ASP.NET has an easy way to return a DataGrid as an MSExcel file:
>>
>>  Dim stringwriter As New System.IO.StringWriter()
>>  Dim htmlwriter As New System.Web.UI.HtmlTextWriter(stringwriter)
>>
>>  DataGrid1.RenderControl(htmlwriter)
>>  Response.AppendHeader("content-disposition",
>>                            "attachment;filename=name.xls")
>>  Response.Write(stringwriter.ToString())
>>  Response.End()
>>
>>  What is nice is that the Excel worksheet reflects the styling of the
>>  DataGrid.  ... I downloaded the "Excel" file produced by the ASP.NET
>>  application, saved it, and opened it in a text editor. The content
>>  was simply the table portion of an HTML file.
>>
>>  How do I do this in Wicket?

Igor Vaynberg: 
> In Wicket 1.2 you can do this:
>
> DataTable dt=...;
>
> add(new Link("export-link") {
>   onclick() {
>       getRequestCycle().setRequestTarget(new
ComponentRequestTarget(dt));
>       WebResponse wr=(WebResponse)getResponse();
>       wr.setHeader(blah);
>   }
> }

I used a submit button in a form.  To make it work I also had to set the
content-type:

protected void onSubmit() {
 getRequestCycle().setRequestTarget(new
ComponentRequestTarget(dataTable));
 WebResponse wr=(WebResponse)getResponse();
 wr.setContentType("excel/ms-excel; name=" + msExcelFilename);
 wr.setHeader("content-disposition",
            "attachment;filename=" + msExcelFilename);
}

It did not reflect the DataTable's stylesheet attributes -- this is not
a showstopper, but can I make it happen?


Of greater concern is that if I try to download the Excel file a second
time (clicking the download button again), I get an error.  If from the
error page I use my browser's back button, my page returns and the
download button works again -- once.

In other words, I must re-request my page between each download request,
or I get an error.  What is actually going on here, and how do I correct
this behavior?  Is it because I am using a submit button instead of a
Link to trigger the download?  How can I change my code to avoid
invalidating the page which offered the download?

Here is the error:

Unexpected RuntimeException
Root cause:java.lang.IllegalStateException: No Page found for component
[MarkupContainer [Component id = 1, page = <No Page>, path =
1.MyDataTable$1]]     at wicket.Component.getPage(Component.java:1033)
at wicket.Component.hasErrorMessage(Component.java:1246)     at
wicket.markup.html.form.Form$14.component(Form.java:808)     at
wicket.MarkupContainer.visitChildren(MarkupContainer.java:670)     at
wicket.MarkupContainer.visitChildren(MarkupContainer.java:685)     at
wicket.MarkupContainer.visitChildren(MarkupContainer.java:685)     at
wicket.MarkupContainer.visitChildren(MarkupContainer.java:710)     at
wicket.markup.html.form.Form.anyFormComponentError(Form.java:804)     at
wicket.markup.html.form.Form.hasError(Form.java:505)     at
wicket.markup.html.form.Form.process(Form.java:702)     at
wicket.markup.html.form.Form.onFormSubmitted(Form.java:245)     at
java.lang.reflect.Method.invoke(Method.java:585)     at
wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:162
)     at
wicket.request.target.component.listener.ListenerInterfaceRequestTarget.
processEvents(ListenerInterfaceRequestTarget.java:74)     at
wicket.request.compound.DefaultEventProcessorStrategy.processEvents(Defa
ultEventProcessorStrategy.java:62)     at
wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEve
nts(AbstractCompoundRequestCycleProcessor.java:57)     at
wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:818)
at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:851)
at wicket.RequestCycle.step(RequestCycle.java:931)     at
wicket.RequestCycle.steps(RequestCycle.java:1005)     at
wicket.RequestCycle.request(RequestCycle.java:451)     at
wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:208)     at
wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:235)     at
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)     at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:252)     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:173)     at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:213)     at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:178)     at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:126)     at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:105)     at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:107)     at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:1
48)     at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:85
6)     at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC
onnection(Http11Protocol.java:744)     at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint
.java:527)     at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollow
erWorkerThread.java:80)     at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
.java:684)     at java.lang.Thread.run(Thread.java:595)Complete
stack:wicket.WicketRuntimeException: Method onFormSubmitted of interface
wicket.markup.html.form.IFormSubmitListener targeted at component
[MarkupContainer [Component id = exportToExcelForm, page =
mem.components.QueryDataPanelTest, path =
9:queryDataPanel:exportToExcelForm.QueryDataPanel$1, isVisible = true,
isVersioned = true]] threw an exception     at
wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:171
)     at
wicket.request.target.component.listener.ListenerInterfaceRequestTarget.
processEvents(ListenerInterfaceRequestTarget.java:74)     at
wicket.request.compound.DefaultEventProcessorStrategy.processEvents(Defa
ultEventProcessorStrategy.java:62)     at
wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEve
nts(AbstractCompoundRequestCycleProcessor.java:57)     at
wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:818)
at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:851)
at wicket.RequestCycle.step(RequestCycle.java:931)     at
wicket.RequestCycle.steps(RequestCycle.java:1005)     at
wicket.RequestCycle.request(RequestCycle.java:451)     at
wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:208)java.lan
g.reflect.InvocationTargetException     at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)     at java.lang.reflect.Method.invoke(Method.java:585)     at
wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:162
)     at
wicket.request.target.component.listener.ListenerInterfaceRequestTarget.
processEvents(ListenerInterfaceRequestTarget.java:74)     at
wicket.request.compound.DefaultEventProcessorStrategy.processEvents(Defa
ultEventProcessorStrategy.java:62)     at
wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEve
nts(AbstractCompoundRequestCycleProcessor.java:57)     at
wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:818)
at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:851)
at wicket.RequestCycle.step(RequestCycle.java:931)     at
wicket.RequestCycle.steps(RequestCycle.java:1005)     at
wicket.RequestCycle.request(RequestCycle.java:451)     at
wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:208)


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to