Class ExportToolbar
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.panel.Panel
-
- org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar
-
- org.apache.wicket.extensions.markup.html.repeater.data.table.export.ExportToolbar
-
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IMetadataContext<Serializable,Component>
,IQueueRegion
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
public class ExportToolbar extends AbstractToolbar
A toolbar that provides links to download the data represented by allIExportableColumn
s in the table exported to formats supported by theIDataExporter
s configured.- Author:
- Jesse Long
- See Also:
IDataExporter
,IExportableColumn
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExportToolbar.DataExportResourceStreamWriter
AnIResourceStreamWriter
which writes the exportable data from a table to an output stream.
-
Field Summary
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Constructor Summary
Constructors Constructor Description ExportToolbar(DataTable<?,?> table)
Creates a new instance with the default message model.ExportToolbar(DataTable<?,?> table, IModel<String> fileNameModel)
Creates a new instance with the provided data table and file name model.ExportToolbar(DataTable<?,?> table, IModel<String> messageModel, IModel<String> fileNameModel)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExportToolbar
addDataExporter(IDataExporter exporter)
Adds aIDataExporter
to the list of data exporters to be used in this toolbar.protected void
calculateVisibility()
This toolbar is only visible if there are rows in the data set and if there are exportable columns in the data table and if there are data exporters added to the toolbar.protected Component
createExportLink(String componentId, IDataExporter dataExporter)
Creates a new link to the exported data for the providedIDataExporter
.protected Duration
getCacheDuration()
How long should the export be cached.IModel<String>
getFileNameModel()
Returns the model of the file name used for the exported data.IModel<String>
getMessageModel()
Returns the model of the export message displayed in the toolbar.protected void
onConfigure()
Called on all components before any component is rendered.protected void
onDetach()
Called to allow a component to detach resources after use.protected void
onInitialize()
This method is meant to be used as an alternative to initialize components.ExportToolbar
setFileNameModel(IModel<String> fileNameModel)
Sets the model of the file name used for the exported data.ExportToolbar
setMessageModel(IModel<String> messageModel)
Sets the models of the export message displayed in the toolbar.-
Methods inherited from class org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar
getTable
-
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
getRegionMarkup, newMarkupSourcingStrategy
-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onBeforeRender, onComponentTag, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IQueueRegion
dequeue, newDequeueContext
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
ExportToolbar
public ExportToolbar(DataTable<?,?> table)
Creates a new instance with the default message model. This instance will use "export." as the exported file name prefix.- Parameters:
table
- The data table this toolbar belongs to.
-
ExportToolbar
public ExportToolbar(DataTable<?,?> table, IModel<String> fileNameModel)
Creates a new instance with the provided data table and file name model.- Parameters:
table
- The table to which this toolbar belongs.fileNameModel
- The model of the file name. This should exclude the file extensions.
-
ExportToolbar
public ExportToolbar(DataTable<?,?> table, IModel<String> messageModel, IModel<String> fileNameModel)
Creates a new instance.- Parameters:
table
- The table to which this toolbar belongs.messageModel
- The model of the export message.fileNameModel
- The model of the file name. This should exclude the file extensions.
-
-
Method Detail
-
setMessageModel
public ExportToolbar setMessageModel(IModel<String> messageModel)
Sets the models of the export message displayed in the toolbar.- Parameters:
messageModel
- the models of the export message displayed in the toolbar.- Returns:
this
, for chaining.
-
setFileNameModel
public ExportToolbar setFileNameModel(IModel<String> fileNameModel)
Sets the model of the file name used for the exported data.- Parameters:
fileNameModel
- The model of the file name used for the exported data.- Returns:
this
, for chaining.
-
getFileNameModel
public IModel<String> getFileNameModel()
Returns the model of the file name used for the exported data.- Returns:
- the model of the file name used for the exported data.
-
getMessageModel
public IModel<String> getMessageModel()
Returns the model of the export message displayed in the toolbar.- Returns:
- the model of the export message displayed in the toolbar.
-
onInitialize
protected void onInitialize()
This method is meant to be used as an alternative to initialize components. Usually the component's constructor is used for this task, but sometimes a component cannot be initialized in isolation, it may need to access its parent component or its markup in order to fully initialize. This method is invoked once per component's lifecycle when a path exists from this component to thePage
thus providing the component with an atomic callback when the component's environment is built out.Overrides must call super#
Component.onInitialize()
. Usually this should be the first thing an override does, much like a constructor.Parent containers are guaranteed to be initialized before their children
It is safe to use
Component.getPage()
in this methodNOTE:The timing of this call is not precise, the contract is that it is called sometime before
Component.onBeforeRender()
.- Overrides:
onInitialize
in classMarkupContainer
-
createExportLink
protected Component createExportLink(String componentId, IDataExporter dataExporter)
Creates a new link to the exported data for the providedIDataExporter
.- Parameters:
componentId
- The component of the link.dataExporter
- The data exporter to use to export the data.- Returns:
- a new link to the exported data for the provided
IDataExporter
.
-
getCacheDuration
protected Duration getCacheDuration()
How long should the export be cached.- Returns:
- default is
Duration.ZERO
-
onConfigure
protected void onConfigure()
Description copied from class:Component
Called on all components before any component is rendered. This method should be used to configure such things as visibility and enabled flags.Overrides must call
super.onConfigure()
, usually before any other codeNOTE: Component hierarchy should not be modified inside this method, instead it should be done in
Component.onBeforeRender()
NOTE: Why this method is preferrable to directly overriding
Component.isVisible()
andComponent.isEnabled()
? Because those methods are called multiple times even for processing of a single request. If they contain expensive logic they can slow down the response time of the entire page. Further, overriding those methods directly on form components may lead to inconsistent or unexpected state depending on when those methods are called in the form processing workflow. It is a better practice to push changes to state rather than pull.NOTE: If component's visibility or another property depends on another component you may call
other.configure()
followed byother.isVisible()
as mentioned inComponent.configure()
javadoc.NOTE: Why should
Component.onBeforeRender()
not be used for this? Because if a component's visibility is controlled insideComponent.onBeforeRender()
, once invisible the component will never become visible again.- Overrides:
onConfigure
in classComponent
-
calculateVisibility
protected void calculateVisibility()
This toolbar is only visible if there are rows in the data set and if there are exportable columns in the data table and if there are data exporters added to the toolbar.
-
onDetach
protected void onDetach()
Description copied from class:Component
Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.- Overrides:
onDetach
in classMarkupContainer
-
addDataExporter
public ExportToolbar addDataExporter(IDataExporter exporter)
Adds aIDataExporter
to the list of data exporters to be used in this toolbar.- Parameters:
exporter
- TheIDataExporter
to add to the toolbar.- Returns:
this
, for chaining.
-
-