Class Image
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.markup.html.WebComponent
-
- org.apache.wicket.markup.html.image.Image
-
- All Implemented Interfaces:
java.io.Serializable,IEventSink,IEventSource,IFeedbackContributor,IConverterLocator,IMetadataContext<java.io.Serializable,Component>,IRequestListener,IHeaderContributor,IRequestableComponent,org.apache.wicket.util.IHierarchical<Component>,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
NonCachingImage,Source
public class Image extends WebComponent implements IRequestListener
An Image component displays localizable image resources.For details of how Images load, generate and manage images, see
LocalizedImageResource. The first ResourceReference / ImageResource is used for the src attribute within the img tag, all following are applied to the srcset. If setXValues(String... values) is used the values are set behind the srcset elements in the order they are given to the setXValues(String... valus) method. The separated values in the sizes attribute are set with setSizes(String... sizes)- Author:
- Jonathan Locke, Tobias Soloschenko
- See Also:
NonCachingImage, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImage.CorsTo be used for the crossOrigin attribute
-
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
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedImage(java.lang.String id)This constructor can be used if you overridegetImageResourceReference()orgetImageResource()Image(java.lang.String id, java.lang.String string)Image(java.lang.String id, IModel<?> model)Image(java.lang.String id, IResource imageResource, IResource... imageResources)Constructs an image directly from an image resource.Image(java.lang.String id, ResourceReference resourceReference, org.apache.wicket.request.mapper.parameter.PageParameters resourceParameters, ResourceReference... resourceReferences)Constructs an image from an image resourcereference.Image(java.lang.String id, ResourceReference resourceReference, ResourceReference... resourceReferences)Constructs an image from an image resourcereference.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAntiCacheParameter(ComponentTag tag)Adds random noise to the url every request to prevent the browser from caching the image.protected voidbuildSizesAttribute(ComponentTag tag)builds the sizes attribute of the img tagprotected java.lang.StringbuildSrcAttribute(ComponentTag tag)Builds the src attributeprotected voidbuildSrcSetAttribute(ComponentTag tag)Builds the srcset attribute if multiple localizedImageResources are found as varargsbooleancanCallListener()Checks whether or not anIRequestListenercan be invoked on this component.Image.CorsgetCrossOrigin()Gets the cross origin settingsprotected IResourcegetImageResource()protected ResourceReferencegetImageResourceReference()protected booleangetStatelessHint()Returns whether the component can be stateless.protected IModel<?>initModel()Called when a null model is about to be retrieved in order to allow a subclass to provide an initial model.protected voidonComponentTag(ComponentTag tag)Processes the component tag.voidonComponentTagBody(MarkupStream markupStream, ComponentTag openTag)Processes the body.voidonRequest()Called when a request is received.voidremoveSizes()Removes all sizes values.voidremoveXValues()Removes all x values from the image src setbooleanrendersPage()Does invocation of this listener render the page.voidsetCrossOrigin(Image.Cors crossOrigin)Sets the cross origin settings
ANONYMOUS: Cross-origin CORS requests for the element will not have the credentials flag set.
USE_CREDENTIALS: Cross-origin CORS requests for the element will have the credentials flag set.
NO_CORS: The empty string is also a valid keyword, and maps to the Anonymous state.ComponentsetDefaultModel(IModel<?> model)Sets the given model.voidsetImageResource(IResource imageResource)voidsetImageResourceReference(ResourceReference resourceReference)voidsetImageResourceReference(ResourceReference resourceReference, org.apache.wicket.request.mapper.parameter.PageParameters parameters)voidsetImageResourceReferences(org.apache.wicket.request.mapper.parameter.PageParameters parameters, ResourceReference... resourceReferences)voidsetImageResources(IResource... imageResources)voidsetSizes(java.lang.String... sizes)voidsetXValues(java.lang.String... values)protected booleanshouldAddAntiCacheParameter()Adding an image toAjaxRequestTargetmost of the times mean that the image has changes and must be re-rendered.-
Methods inherited from class org.apache.wicket.markup.html.WebComponent
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession, onRender
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, get, 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, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, internalInitialize, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onConfigure, onDetach, onEvent, onInitialize, 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, toString, toString, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
-
-
-
Constructor Detail
-
Image
protected Image(java.lang.String id)
This constructor can be used if you overridegetImageResourceReference()orgetImageResource()- Parameters:
id-
-
Image
public Image(java.lang.String id, ResourceReference resourceReference, ResourceReference... resourceReferences)Constructs an image from an image resourcereference. That resource reference will bind its resource to the current SharedResources. If you are using non sticky session clustering and the resource reference is pointing to a Resource that isn't guaranteed to be on every server, for example a dynamic image or resources that aren't added with a IInitializer at application startup. Then if only that resource is requested from another server, without the rendering of the page, the image won't be there and will result in a broken link.- Parameters:
id- See ComponentresourceReference- The shared image resource used in the src attributeresourceReferences- The shared image resources used in the srcset attribute
-
Image
public Image(java.lang.String id, ResourceReference resourceReference, org.apache.wicket.request.mapper.parameter.PageParameters resourceParameters, ResourceReference... resourceReferences)Constructs an image from an image resourcereference. That resource reference will bind its resource to the current SharedResources. If you are using non sticky session clustering and the resource reference is pointing to a Resource that isn't guaranteed to be on every server, for example a dynamic image or resources that aren't added with a IInitializer at application startup. Then if only that resource is requested from another server, without the rendering of the page, the image won't be there and will result in a broken link.- Parameters:
id- See ComponentresourceReference- The shared image resource used in the src attributeresourceParameters- The resource parametersresourceReferences- The shared image resources used in the srcset attribute
-
Image
public Image(java.lang.String id, IResource imageResource, IResource... imageResources)Constructs an image directly from an image resource. This one doesn't have the 'non sticky session clustering' problem that the ResourceReference constructor has. But this will result in a non 'stable' url and the url will have request parameters.- Parameters:
id- See ComponentimageResource- The image resource used in the src attributeimageResources- The image resource used in the srcset attribute
-
Image
public Image(java.lang.String id, IModel<?> model)- See Also:
Component(String, IModel)
-
Image
public Image(java.lang.String id, java.lang.String string)- Parameters:
id- See Componentstring- Name of image- See Also:
Component(String, IModel)
-
-
Method Detail
-
rendersPage
public boolean rendersPage()
Description copied from interface:IRequestListenerDoes invocation of this listener render the page.- Specified by:
rendersPagein interfaceIRequestListener- Returns:
- default
true, i.e. aRenderPageRequestHandleris schedules after invocation
-
onRequest
public void onRequest()
Description copied from interface:IRequestListenerCalled when a request is received.- Specified by:
onRequestin interfaceIRequestListener- See Also:
org.apache.wicket.IResourceListener#onResourceRequested()
-
setImageResource
public void setImageResource(IResource imageResource)
- Parameters:
imageResource- The new ImageResource to set.
-
setImageResources
public void setImageResources(IResource... imageResources)
- Parameters:
imageResources- the new ImageResource to set.
-
setImageResourceReference
public void setImageResourceReference(ResourceReference resourceReference)
- Parameters:
resourceReference- The shared ImageResource to set.
-
setImageResourceReference
public void setImageResourceReference(ResourceReference resourceReference, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
- Parameters:
resourceReference- The resource reference to set.parameters- the parameters to be applied to the localized image resource
-
setImageResourceReferences
public void setImageResourceReferences(org.apache.wicket.request.mapper.parameter.PageParameters parameters, ResourceReference... resourceReferences)- Parameters:
parameters- Set the resource parameters for the resource.resourceReferences- The resource references to set.
-
setXValues
public void setXValues(java.lang.String... values)
- Parameters:
values- the x values to be used in the srcset
-
removeXValues
public void removeXValues()
Removes all x values from the image src set
-
setSizes
public void setSizes(java.lang.String... sizes)
- Parameters:
sizes- the sizes to be used in the size
-
removeSizes
public void removeSizes()
Removes all sizes values. The corresponding attribute will not be rendered anymore.
-
setDefaultModel
public Component setDefaultModel(IModel<?> model)
Description copied from class:ComponentSets the given model.WARNING: DO NOT OVERRIDE THIS METHOD UNLESS YOU HAVE A VERY GOOD REASON FOR IT. OVERRIDING THIS MIGHT OPEN UP SECURITY LEAKS AND BREAK BACK-BUTTON SUPPORT.
- Overrides:
setDefaultModelin classComponent- Parameters:
model- The model- Returns:
- This
- See Also:
Component.setDefaultModel(org.apache.wicket.model.IModel)
-
getImageResource
protected IResource getImageResource()
- Returns:
- Resource returned from subclass
-
getImageResourceReference
protected ResourceReference getImageResourceReference()
- Returns:
- ResourceReference returned from subclass
-
initModel
protected IModel<?> initModel()
Description copied from class:ComponentCalled when a null model is about to be retrieved in order to allow a subclass to provide an initial model.By default this implementation looks components in the parent chain owning a
IComponentInheritedModelto provide a model for this component viaIComponentInheritedModel.wrapOnInheritance(Component).For example a
FormComponenthas the opportunity to instantiate a model on the fly using itsidand the containingForm's model, if the form holds aCompoundPropertyModel.- Overrides:
initModelin classComponent- Returns:
- The model
- See Also:
Component.initModel()
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Description copied from class:ComponentProcesses the component tag. Overrides of this method most likely should call the super implementation.- Overrides:
onComponentTagin classComponent- Parameters:
tag- Tag to modify- See Also:
Component.onComponentTag(ComponentTag)
-
buildSrcSetAttribute
protected void buildSrcSetAttribute(ComponentTag tag)
Builds the srcset attribute if multiple localizedImageResources are found as varargs- Parameters:
tag- the component tag
-
buildSrcAttribute
protected java.lang.String buildSrcAttribute(ComponentTag tag)
Builds the src attribute- Parameters:
tag- the component tag- Returns:
- the value of the src attribute
-
buildSizesAttribute
protected void buildSizesAttribute(ComponentTag tag)
builds the sizes attribute of the img tag- Parameters:
tag- the component tag
-
shouldAddAntiCacheParameter
protected boolean shouldAddAntiCacheParameter()
Adding an image toAjaxRequestTargetmost of the times mean that the image has changes and must be re-rendered.With this method the user may change this default behavior for some of her images.
- Returns:
trueto add the anti cache request parameter,false- otherwise
-
addAntiCacheParameter
protected void addAntiCacheParameter(ComponentTag tag)
Adds random noise to the url every request to prevent the browser from caching the image.- Parameters:
tag-
-
getStatelessHint
protected boolean getStatelessHint()
Description copied from class:ComponentReturns whether the component can be stateless. Also the component behaviors must be stateless, otherwise the component will be treat as stateful. In order for page to be stateless (and not to be stored in session), all components (and component behaviors) must be stateless.- Overrides:
getStatelessHintin classComponent- Returns:
- whether the component can be stateless
- See Also:
Component.getStatelessHint()
-
onComponentTagBody
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
Description copied from class:ComponentProcesses the body.- Overrides:
onComponentTagBodyin classComponent- Parameters:
markupStream- The markup streamopenTag- The open tag for the body- See Also:
Component.onComponentTagBody(MarkupStream, ComponentTag)
-
canCallListener
public boolean canCallListener()
Description copied from class:ComponentChecks whether or not anIRequestListenercan be invoked on this component. Usually components deny these invocations if they are either invisible or disabled in hierarchy.WARNING: be careful when overriding this method because it may open security holes - such as allowing a user to click on a link that should be disabled.
Example usecase for overriding: Suppose you are building an component that displays images. The component generates a callback to itself using
IRequestListenerinterface and uses this callback to stream image data. If such a component is placed inside a disabledWebMarkupContainerwe still want to allow the invocation of the request listener callback method so that image data can be streamed. Such a component would override this method and return true.- Overrides:
canCallListenerin classComponent- Returns:
- true iff the listener method can be invoked on this component
-
getCrossOrigin
public Image.Cors getCrossOrigin()
Gets the cross origin settings- Returns:
- the cross origins settings
-
setCrossOrigin
public void setCrossOrigin(Image.Cors crossOrigin)
Sets the cross origin settings
ANONYMOUS: Cross-origin CORS requests for the element will not have the credentials flag set.
USE_CREDENTIALS: Cross-origin CORS requests for the element will have the credentials flag set.
NO_CORS: The empty string is also a valid keyword, and maps to the Anonymous state. The attribute's invalid value default is the Anonymous state. The missing value default, used when the attribute is omitted, is the No CORS state- Parameters:
crossOrigin- the cross origins settings to set
-
-