Class Image

    • Constructor Detail

      • Image

        public Image​(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 Component
        resourceReference - The shared image resource used in the src attribute
        resourceReferences - The shared image resources used in the srcset attribute
      • Image

        public Image​(String id,
                     ResourceReference resourceReference,
                     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 Component
        resourceReference - The shared image resource used in the src attribute
        resourceParameters - The resource parameters
        resourceReferences - The shared image resources used in the srcset attribute
      • Image

        public Image​(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 Component
        imageResource - The image resource used in the src attribute
        imageResources - The image resource used in the srcset attribute
    • Method Detail

      • 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.
      • setXValues

        public void setXValues​(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​(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.
      • buildSrcSetAttribute

        protected void buildSrcSetAttribute​(ComponentTag tag)
        Builds the srcset attribute if multiple localizedImageResources are found as varargs
        Parameters:
        tag - the component tag
      • buildSrcAttribute

        protected 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 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 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()
      • canCallListener

        public boolean canCallListener()
        Description copied from class: Component
        Checks whether or not an IRequestListener can 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 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.

        Overrides:
        canCallListener in class Component
        Returns:
        true iff the listener method can be invoked on this component
      • setCrossOrigin

        public void setCrossOrigin​(CrossOrigin 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