public class AjaxDownloadBehavior extends AbstractDefaultAjaxBehavior
Usage:
final AjaxDownload download = new AjaxDownload(resource); add(download); add(new AjaxButton("download") { @Override protected void onSubmit(IPartialPageRequestHandler handler, Form<?> form) { download.initiate(handler); } });
To set the name of the downloaded resource make use of
ResourceStreamResource.setFileName(String)
or
AbstractResource.ResourceResponse.setFileName(String)
Modifier and Type | Class and Description |
---|---|
static class |
AjaxDownloadBehavior.Location |
INDICATOR
Constructor and Description |
---|
AjaxDownloadBehavior(IResource resource)
Download of a
IResource . |
AjaxDownloadBehavior(ResourceReference reference)
Download of a
ResourceReference . |
AjaxDownloadBehavior(ResourceReference reference,
PageParameters resourceParameters)
Download of a
ResourceReference . |
Modifier and Type | Method and Description |
---|---|
AjaxDownloadBehavior.Location |
getLocation() |
void |
initiate(AjaxRequestTarget target)
Deprecated.
|
void |
initiate(IPartialPageRequestHandler handler)
Call this method to initiate the download.
|
static void |
markCompleted(IResource.Attributes attributes)
Mark a resource as complete.
|
protected void |
onBeforeDownload(AjaxRequestTarget target)
Deprecated.
|
protected void |
onBeforeDownload(IPartialPageRequestHandler handler) |
protected void |
onBind()
Subclasses should call super.onBind()
|
protected void |
onDownloadCompleted(AjaxRequestTarget target)
A callback executed when the download of the resource finished successfully or with a failure.
|
protected void |
onDownloadFailed(AjaxRequestTarget target)
A callback executed when the download of the resource failed for some reason,
e.g.
|
protected void |
onDownloadSuccess(AjaxRequestTarget target)
A callback executed when the download of the resource finished successfully.
|
protected void |
onUnbind()
Called when the behavior is removed from its component.
|
void |
renderHead(Component component,
IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.
|
protected void |
respond(AjaxRequestTarget target) |
AjaxDownloadBehavior |
setLocation(AjaxDownloadBehavior.Location location) |
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onMethodMismatch, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributes, updateAjaxAttributes
afterRender, bind, getCallbackUrl, getComponent, onComponentRendered, onComponentTag, onComponentTag, unbind
beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, onRemove, onTag
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
rendersPage
public AjaxDownloadBehavior(IResource resource)
IResource
.resource
- resource to downloadpublic AjaxDownloadBehavior(ResourceReference reference)
ResourceReference
.
The IResource
returned by ResourceReference.getResource()
must call
#markCompleted(Attributes)
when responding, otherwise the callback
#onDownloadSuccess(IPartialPageRequestHandler)
will not work.
reference
- reference to resource to downloadpublic AjaxDownloadBehavior(ResourceReference reference, PageParameters resourceParameters)
ResourceReference
.
The IResource
returned by ResourceReference.getResource()
must call
#markCompleted(Attributes)
when responding, otherwise the callback
#onDownloadSuccess(IPartialPageRequestHandler)
will not work.
reference
- reference to resource to downloadresourceParameters
- parameters for the resourceprotected void onBind()
AbstractDefaultAjaxBehavior
onBind
in class AbstractDefaultAjaxBehavior
AbstractAjaxBehavior.onBind()
protected void onUnbind()
AbstractAjaxBehavior
onUnbind
in class AbstractAjaxBehavior
@Deprecated public void initiate(AjaxRequestTarget target)
public void initiate(IPartialPageRequestHandler handler)
handler
- the initiating RequestHandler@Deprecated protected void onBeforeDownload(AjaxRequestTarget target)
onBeforeDownload(IPartialPageRequestHandler)
insteadtarget
- protected void onBeforeDownload(IPartialPageRequestHandler handler)
protected void onDownloadSuccess(AjaxRequestTarget target)
target
- The Ajax request handlerprotected void onDownloadFailed(AjaxRequestTarget target)
Since the HTTP status code of the download is not available to Wicket, any HTML in the resource response
will be interpreted as a failure HTTP status message. Thus is it not possible to download HTML resources
via AjaxDownloadBehavior
.
target
- The Ajax request handlerprotected void onDownloadCompleted(AjaxRequestTarget target)
target
- The Ajax request handlerpublic void renderHead(Component component, IHeaderResponse response)
Behavior
renderHead
in interface IComponentAwareHeaderContributor
renderHead
in class AbstractDefaultAjaxBehavior
component
- component which is contributing to the response. This parameter is here to give
the component as the context for component-awares implementing this interfaceresponse
- Response objectBehavior.renderHead(Component,
org.apache.wicket.markup.head.IHeaderResponse)
protected void respond(AjaxRequestTarget target)
respond
in class AbstractDefaultAjaxBehavior
target
- The AJAX targetpublic AjaxDownloadBehavior.Location getLocation()
public AjaxDownloadBehavior setLocation(AjaxDownloadBehavior.Location location)
public static void markCompleted(IResource.Attributes attributes)
Has to be called from IResource.respond(Attributes)
when downloaded via
AjaxDownloadBehavior(IResource)
.
attributes
- resource attributesCopyright © 2006–2022 Apache Software Foundation. All rights reserved.