org.apache.wicket.markup.html.image
Class Image

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.markup.html.WebComponent
          extended by org.apache.wicket.markup.html.image.Image
All Implemented Interfaces:
java.io.Serializable, IEventSink, IEventSource, IClusterable, IConverterLocator, IRequestListener, IResourceListener, IHeaderContributor, IRequestableComponent, IHierarchical<Component>
Direct Known Subclasses:
NonCachingImage

public class Image
extends WebComponent
implements IResourceListener

An Image component displays a localizable image resource.

For details of how Images load, generate and manage images, see LocalizedImageResource.

Author:
Jonathan Locke
See Also:
NonCachingImage, Serialized Form

Field Summary
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
protected Image(java.lang.String id)
          This constructor can be used if you override getImageResourceReference() or getImageResource()
  Image(java.lang.String id, IModel<?> model)
           
  Image(java.lang.String id, IResource imageResource)
          Constructs an image directly from an image resource.
  Image(java.lang.String id, ResourceReference resourceReference)
          Constructs an image from an image resourcereference.
  Image(java.lang.String id, ResourceReference resourceReference, PageParameters resourceParameters)
          Constructs an image from an image resourcereference.
  Image(java.lang.String id, java.lang.String string)
           
 
Method Summary
protected  void addAntiCacheParameter(ComponentTag tag)
          Adds random noise to the url every request to prevent the browser from caching the image.
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.
 Component setDefaultModel(IModel<?> model)
          Sets the given model.
 void setImageResource(IResource imageResource)
           
 void setImageResourceReference(ResourceReference resourceReference)
           
 void setImageResourceReference(ResourceReference resourceReference, PageParameters parameters)
           
protected  boolean shouldAddAntiCacheParameter()
          Adding an image to AjaxRequestTarget most of the times mean that the image has changes and must be re-rendered.
 
Methods inherited from class org.apache.wicket.markup.html.WebComponent
onRender
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, 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, getFeedbackMessage, 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, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onAfterRenderChildren, onBeforeRender, onConfigure, onDetach, onEvent, onInitialize, onMarkupAttached, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, 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, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Image

protected Image(java.lang.String id)
This constructor can be used if you override getImageResourceReference() or getImageResource()

Parameters:
id -

Image

public Image(java.lang.String id,
             ResourceReference resourceReference)
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 Component
resourceReference - The shared image resource

Image

public Image(java.lang.String id,
             ResourceReference resourceReference,
             PageParameters resourceParameters)
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 Component
resourceReference - The shared image resource
resourceParameters - The resource parameters

Image

public Image(java.lang.String id,
             IResource imageResource)
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 Component
imageResource - The image resource

Image

public Image(java.lang.String id,
             IModel<?> model)
See Also:
Component.Component(String, IModel)

Image

public Image(java.lang.String id,
             java.lang.String string)
Parameters:
id - See Component
string - Name of image
See Also:
Component.Component(String, IModel)
Method Detail

onResourceRequested

public void onResourceRequested()
Description copied from interface: IResourceListener
Called when a resource is requested.

Specified by:
onResourceRequested in interface IResourceListener
See Also:
IResourceListener.onResourceRequested()

setImageResource

public void setImageResource(IResource imageResource)
Parameters:
imageResource - The new ImageResource to set.

setImageResourceReference

public void setImageResourceReference(ResourceReference resourceReference)
Parameters:
resourceReference - The shared ImageResource to set.

setImageResourceReference

public void setImageResourceReference(ResourceReference resourceReference,
                                      PageParameters parameters)
Parameters:
resourceReference - The shared ImageResource to set.
parameters - Set the resource parameters for the resource.

setDefaultModel

public Component setDefaultModel(IModel<?> model)
Description copied from class: Component
Sets 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:
setDefaultModel in class Component
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: Component
Called when a null model is about to be retrieved in order to allow a subclass to provide an initial model. This gives FormComponent, for example, an opportunity to instantiate a model on the fly using the containing Form's model.

Overrides:
initModel in class Component
Returns:
The model
See Also:
Component.initModel()

onComponentTag

protected void onComponentTag(ComponentTag tag)
Description copied from class: Component
Processes the component tag. Overrides of this method most likely should call the super implementation.

Overrides:
onComponentTag in class Component
Parameters:
tag - Tag to modify
See Also:
Component.onComponentTag(ComponentTag)

shouldAddAntiCacheParameter

protected boolean shouldAddAntiCacheParameter()
Adding an image to 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.

Returns:
true to add the anti cache request parameter, false - otherwise

addAntiCacheParameter

protected final 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: Component
Returns 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:
getStatelessHint in class Component
Returns:
whether the component can be stateless
See Also:
Component.getStatelessHint()

onComponentTagBody

public void onComponentTagBody(MarkupStream markupStream,
                               ComponentTag openTag)
Description copied from class: Component
Processes the body.

Overrides:
onComponentTagBody in class Component
Parameters:
markupStream - The markup stream
openTag - The open tag for the body
See Also:
Component.onComponentTagBody(MarkupStream, ComponentTag)


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.