public class Image extends WebComponent implements IResourceListener
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)
NonCachingImage,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
Image.Cors
To be used for the crossOrigin attribute
|
ENABLE, FLAG_AFTER_RENDERING, FLAG_INITIALIZED, FLAG_PREPARED_FOR_RENDER, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RENDERING, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEINGINTERFACE| Modifier | Constructor and Description |
|---|---|
protected |
Image(String id)
This constructor can be used if you override
getImageResourceReference() or
getImageResource() |
|
Image(String id,
IModel<?> model) |
|
Image(String id,
IResource imageResource,
IResource... imageResources)
Constructs an image directly from an image resource.
|
|
Image(String id,
ResourceReference resourceReference,
PageParameters resourceParameters,
ResourceReference... resourceReferences)
Constructs an image from an image resourcereference.
|
|
Image(String id,
ResourceReference resourceReference,
ResourceReference... resourceReferences)
Constructs an image from an image resourcereference.
|
|
Image(String id,
String string) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addAntiCacheParameter(ComponentTag tag)
Adds random noise to the url every request to prevent the browser from caching the image.
|
protected void |
buildSizesAttribute(ComponentTag tag)
builds the sizes attribute of the img tag
|
protected String |
buildSrcAttribute(ComponentTag tag)
Builds the src attribute
|
protected void |
buildSrcSetAttribute(ComponentTag tag)
Builds the srcset attribute if multiple localizedImageResources are found as varargs
|
boolean |
canCallListenerInterface(Method method)
Checks whether or not a listener method can be invoked on this component.
|
Image.Cors |
getCrossOrigin()
Gets the cross origin settings
|
protected IResource |
getImageResource() |
protected ResourceReference |
getImageResourceReference() |
protected boolean |
getStatelessHint()
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 void |
onComponentTag(ComponentTag tag)
Processes the component tag.
|
void |
onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag)
Processes the body.
|
void |
onResourceRequested()
Called when a resource is requested.
|
void |
removeSizes()
Removes all sizes values.
|
void |
removeXValues()
Removes all x values from the image src set
|
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. |
Component |
setDefaultModel(IModel<?> model)
Sets the given model.
|
void |
setImageResource(IResource imageResource) |
void |
setImageResourceReference(ResourceReference resourceReference) |
void |
setImageResourceReference(ResourceReference resourceReference,
PageParameters parameters) |
void |
setImageResourceReferences(PageParameters parameters,
ResourceReference... resourceReferences) |
void |
setImageResources(IResource... imageResources) |
void |
setSizes(String... sizes) |
void |
setXValues(String... values) |
protected boolean |
shouldAddAntiCacheParameter()
Adding an image to
AjaxRequestTarget most of the times mean
that the image has changes and must be re-rendered. |
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession, onRenderadd, addStateChange, afterRender, beforeRender, canCallListenerInterfaceAfterExpiry, 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, internalPrepareForRender, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onAfterRenderChildren, onBeforeRender, onConfigure, onDetach, onEvent, onInitialize, onModelChanged, onModelChanging, onReAdd, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, toString, toString, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, visitParents, warn, wrapprotected Image(String id)
getImageResourceReference() or
getImageResource()id - public Image(String id, ResourceReference resourceReference, ResourceReference... resourceReferences)
id - See ComponentresourceReference - The shared image resource used in the src attributeresourceReferences - The shared image resources used in the srcset attributepublic Image(String id, ResourceReference resourceReference, PageParameters resourceParameters, ResourceReference... resourceReferences)
id - See ComponentresourceReference - The shared image resource used in the src attributeresourceParameters - The resource parametersresourceReferences - The shared image resources used in the srcset attributepublic Image(String id, IResource imageResource, IResource... imageResources)
id - See ComponentimageResource - The image resource used in the src attributeimageResources - The image resource used in the srcset attributepublic Image(String id, IModel<?> model)
Component.Component(String, IModel)public Image(String id, String string)
id - See Componentstring - Name of imageComponent.Component(String, IModel)public void onResourceRequested()
IResourceListeneronResourceRequested in interface IResourceListenerIResourceListener.onResourceRequested()public void setImageResource(IResource imageResource)
imageResource - The new ImageResource to set.public void setImageResources(IResource... imageResources)
imageResources - the new ImageResource to set.public void setImageResourceReference(ResourceReference resourceReference)
resourceReference - The shared ImageResource to set.public void setImageResourceReference(ResourceReference resourceReference, PageParameters parameters)
resourceReference - The resource reference to set.parameters - the parameters to be applied to the localized image resourcepublic void setImageResourceReferences(PageParameters parameters, ResourceReference... resourceReferences)
parameters - Set the resource parameters for the resource.resourceReferences - The resource references to set.public void setXValues(String... values)
values - the x values to be used in the srcsetpublic void removeXValues()
public void setSizes(String... sizes)
sizes - the sizes to be used in the sizepublic void removeSizes()
public Component setDefaultModel(IModel<?> model)
ComponentWARNING: 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.
setDefaultModel in class Componentmodel - The modelComponent.setDefaultModel(org.apache.wicket.model.IModel)protected IResource getImageResource()
protected ResourceReference getImageResourceReference()
protected IModel<?> initModel()
Component
By default this implementation looks components in the parent chain owning a
IComponentInheritedModel to provide a model for this component via
IComponentInheritedModel.wrapOnInheritance(Component).
For example a FormComponent has the opportunity to instantiate a model on the fly
using its id and the containing Form's model, if the form holds a
CompoundPropertyModel.
initModel in class ComponentComponent.initModel()protected void onComponentTag(ComponentTag tag)
ComponentonComponentTag in class Componenttag - Tag to modifyComponent.onComponentTag(ComponentTag)protected void buildSrcSetAttribute(ComponentTag tag)
tag - the component tagprotected String buildSrcAttribute(ComponentTag tag)
tag - the component tagprotected void buildSizesAttribute(ComponentTag tag)
tag - the component tagprotected boolean shouldAddAntiCacheParameter()
AjaxRequestTarget most 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.
true to add the anti cache request parameter, false - otherwiseprotected void addAntiCacheParameter(ComponentTag tag)
tag - protected boolean getStatelessHint()
ComponentgetStatelessHint in class ComponentComponent.getStatelessHint()public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
ComponentonComponentTagBody in class ComponentmarkupStream - The markup streamopenTag - The open tag for the bodyComponent.onComponentTagBody(MarkupStream, ComponentTag)public boolean canCallListenerInterface(Method method)
ComponentWARNING: 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 IRequestListener interface and
uses this callback to stream image data. If such a component is placed inside a disabled
webmarkupcontainer we 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 if the listener method belongs to IRequestListener.
canCallListenerInterface in class Componentmethod - listener method about to be invoked on this component. Could be null - in
this case it means any method.public Image.Cors getCrossOrigin()
#setCrossOrigin(Cors)}public void setCrossOrigin(Image.Cors crossOrigin)
crossOrigin - the cross origins settings to setCopyright © 2006–2021 Apache Software Foundation. All rights reserved.