Thank you for a super fast response. As far as I can see Meier, Barreiro and
Deu-Pons applied the same approach
but in a more professional way.
They do:
String url = getCallbackUrl().toString();
(...)
// the timeout is needed to let Wicket release the channel
target.appendJavaScript("setTimeout(\"window.location.href='" + url +"'\",
100);");
And I simply do:
target.appendJavaScript("window.location='" + b.getCallbackUrl() + "'");
They have also set the content disposition to the resource handler:
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
Anyway, thank you for your answer, the link you have attached:
https://cwiki.apache.org/WICKET/ajax-update-and-file-download-in-one-blow.html
is the answer I was looking for.
Robert
W dniu 2012-03-05 16:26, Martin Grigorov pisze:
Hi,
I'm not sure that this really works.
With your code the Ajax request will end with .csv response, not with
<ajax-response>. The indicator may disappear but the .csv data wont be
presented to the user/browser. It will be swallowed in the ajax
response.
I think you need
https://cwiki.apache.org/WICKET/ajax-update-and-file-download-in-one-blow.html
On Mon, Mar 5, 2012 at 5:13 PM, Robert Szmurlo<rob...@iem.pw.edu.pl> wrote:
Hello everyone,
this my first post to the list, so I would like to give many thanks to the
authors and all contributors to the great Apache Wicket project. We silently
develop a medium sized application for over two years (at the Warsaw
University of Technology), and usually we have resolved all issues by
searching answers on this users group or by googling them. This time I would
ask you for consultation.
My goal is to provide a download link for CSV data which will be generated
dynamically and during the time consuming generation I would like to show a
user an indicator. Like the one the IndicatingAjaxLink class do.
My questions are:
1) Is the following source code created the 'wicket way' or I am breaking
somewhere else opened door?
The 'trick' I have employed, that I am not sure of, is the redirection to
the AbstractDefaultAjaxBehaviour in the onClick method of the
IndicatingAjaxLink.
2) The problem with this code is that, when I click the download link the
second time the indicator is not revolving. It is being displayed correctly,
and hidden on time, and the CSV data is exported correctly. The problem is
that the indicator is not moving.
Thank you for you assitance in advance,
Robert Szmurlo
Java:
public class HomePage extends WebPage {
private AbstractDefaultAjaxBehavior b;
private String data = null;
public HomePage(final PageParameters parameters) {
final ByteArrayResource bar = new ByteArrayResource("text/csv") {
@Override
public byte[] getData(Attributes attributes) {
byte[] bytes = null;
try {
bytes = data.getBytes();
} catch (Exception e) {
e.printStackTrace();
}
return bytes;
}
@Override
protected void configureResponse(ResourceResponse
response,Attributes attributes) {
super.configureResponse(response, attributes);
response.setFileName("report.csv");
}
};
add( b = new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
getRequestCycle().scheduleRequestHandlerAfterCurrent(new
ResourceRequestHandler(bar, getPageParameters()));
}
});
add( new IndicatingAjaxLink<Void>("link") {
@Override
public void onClick(AjaxRequestTarget target) {
prepareData(); // takes some time
if (target != null) {
*target.appendJavaScript("window.location='" + b.getCallbackUrl() + "'");*
}
}
});
}
protected void prepareData() {
////////// JUST FOR TEST
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
/////////////////////////
// atach data?
data = "No.;Name\n" +
"1.;John\n" +
"2.;Mary";
}
}
HTML:
<html>
<body>
<a wicket:id="link">Export CSV</a>
</body>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org