Class AjaxDownloadBehavior
- All Implemented Interfaces:
Serializable,IComponentAwareEventSink,IRequestListener,IComponentAwareHeaderContributor,org.apache.wicket.util.io.IClusterable
Usage:
final AjaxDownloadBehavior download = new AjaxDownloadBehavior(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)
- Author:
- svenmeier, Martin Grigorov, Maxim Solodovnik
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR -
Constructor Summary
ConstructorsConstructorDescriptionAjaxDownloadBehavior(IResource resource) Download of aIResource.AjaxDownloadBehavior(ResourceReference reference) Download of aResourceReference.AjaxDownloadBehavior(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters resourceParameters) Download of aResourceReference. -
Method Summary
Modifier and TypeMethodDescriptionvoidinitiate(IPartialPageRequestHandler handler) Call this method to initiate the download.voidinitiate(IPartialPageRequestHandler handler, org.apache.wicket.request.mapper.parameter.PageParameters resourceParameters) Call this method to initiate the download.static voidmarkCompleted(IResource.Attributes attributes) Mark a resource as complete.static voidmarkCompleted(IResource.Attributes attributes, CookieDefaults.SameSite sameSite) Mark a resource as complete.protected voidprotected voidonBind()protected voidonDownloadCompleted(AjaxRequestTarget target) A callback executed when the download of the resource finished successfully or with a failure.protected voidonDownloadFailed(AjaxRequestTarget target) A callback executed when the download of the resource failed for some reason, e.g. an error at the server side.protected voidonDownloadSuccess(AjaxRequestTarget target) A callback executed when the download of the resource finished successfully.protected voidonUnbind()voidrenderHead(Component component, IHeaderResponse response) protected voidrespond(AjaxRequestTarget target) setLocation(AjaxDownloadBehavior.Location location) voidsetSameSite(CookieDefaults.SameSite sameSite) Setter for the sameCookieDefaults.SameSiteMethods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onMethodMismatch, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributes, updateAjaxAttributesMethods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
afterRender, bind, getCallbackUrl, getComponent, onComponentRendered, onComponentTag, onComponentTag, unbindMethods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, onRemove, onTagMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.wicket.IRequestListener
rendersPage
-
Constructor Details
-
AjaxDownloadBehavior
Download of aIResource.- Parameters:
resource- resource to download
-
AjaxDownloadBehavior
Download of aResourceReference.The
IResourcereturned byResourceReference.getResource()must callmarkCompleted(Attributes)when responding, otherwise the callbackonDownloadSuccess(AjaxRequestTarget)will not work.- Parameters:
reference- reference to resource to download
-
AjaxDownloadBehavior
public AjaxDownloadBehavior(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters resourceParameters) Download of aResourceReference.The
IResourcereturned byResourceReference.getResource()must callmarkCompleted(Attributes)when responding, otherwise the callbackonDownloadSuccess(AjaxRequestTarget)will not work.- Parameters:
reference- reference to resource to downloadresourceParameters- parameters for the resource
-
-
Method Details
-
onBind
- Overrides:
onBindin classAbstractDefaultAjaxBehavior
-
onUnbind
- Overrides:
onUnbindin classAbstractAjaxBehavior
-
initiate
public void initiate(IPartialPageRequestHandler handler, org.apache.wicket.request.mapper.parameter.PageParameters resourceParameters) Call this method to initiate the download. You can use theresourceParametersto dynamically pass information to theIResourcein order to generate contents.- Parameters:
handler- the initiating RequestHandlerresourceParameters- Some PageParameters that might be used by the resource in order to generate content
-
initiate
Call this method to initiate the download.- Parameters:
handler- the initiating RequestHandler
-
onBeforeDownload
-
onDownloadSuccess
A callback executed when the download of the resource finished successfully.- Parameters:
target- The Ajax request handler
-
onDownloadFailed
A callback executed when the download of the resource failed for some reason, e.g. an error at the server side.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.- Parameters:
target- The Ajax request handler
-
onDownloadCompleted
A callback executed when the download of the resource finished successfully or with a failure.- Parameters:
target- The Ajax request handler
-
renderHead
- Specified by:
renderHeadin interfaceIComponentAwareHeaderContributor- Overrides:
renderHeadin classAbstractDefaultAjaxBehavior
-
respond
- Specified by:
respondin classAbstractDefaultAjaxBehavior
-
getLocation
-
setLocation
-
markCompleted
Mark a resource as complete.Has to be called from
IResource.respond(Attributes)when downloaded viaAjaxDownloadBehavior(IResource).- Parameters:
attributes- resource attributes
-
markCompleted
Mark a resource as complete.Has to be called from
IResource.respond(Attributes)when downloaded viaAjaxDownloadBehavior(IResource).- Parameters:
attributes- resource attributessameSite- The same site attribute used to mark a download completed.
-
getSameSite
- Returns:
- The
CookieDefaults.SameSiteattribute to be used for the complete download.
-
setSameSite
Setter for the sameCookieDefaults.SameSite- Parameters:
sameSite- The non-null sameSite attribute
-