final AJAXDownload download = new AJAXDownload() {
@Override
protected IResourceStream getResourceStream() {
return new FileResourceStream(theDatabase.getFile());
}
@Override
protected String getFileName() {
return theDatabase.getFile().getAbsoluteFile().getName(); //FIX!!! the
filename gets .html appended to it.
}
};
add(download);
add( new AjaxLink("download") {
public void onClick( AjaxRequestTarget target ) {
if( theDatabase.isOpen() ) {
target.appendJavascript( "alert('The database is open,
close or pause the
db first.');" );
} else {
download.initiate( target );
}
}
});
And this class is unchanged:
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import
org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
import org.apache.wicket.util.resource.IResourceStream;
/**
* @author Sven Meier
* @author Ernesto Reinaldo Barreiro ([email protected])
*/
public abstract class AJAXDownload extends AbstractAjaxBehavior
{
/**
* Call this method to initiate the download.
*/
public void initiate(AjaxRequestTarget target)
{
CharSequence url = getCallbackUrl();
target.appendJavascript("window.location.href='" + url + "'");
}
public void onRequest()
{
getComponent().getRequestCycle().setRequestTarget(
new
ResourceStreamRequestTarget(getResourceStream(), getFileName()));
}
/**
* @see ResourceStreamRequestTarget#getFileName()
*/
protected String getFileName()
{
return null;
}
/**
* Hook method providing the actual resource stream.
*/
protected abstract IResourceStream getResourceStream();
}
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Initiating-File-Download-through-Ajax-is-not-working-tp2289784p3071816.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]