Class WContent

  • All Implemented Interfaces:
    Targetable, WComponent, WebComponent, Serializable

    public class WContent
    extends AbstractWComponent
    implements Targetable

    This wcomponent enables the display of arbitrary document content from a WComponent application. This component does not by default display anything until the display() method is called. It then causes the browser to access the content through the WContentHelperServlet.

    By default, the browser will display the content in a new window, but the setDisplayMode(DisplayMode) method can be used to display the content inline or prompt the user to save the content to a file.

    Since:
    1.0.0
    Author:
    Martin Shevchenko
    See Also:
    Serialized Form
    • Field Detail

      • URL_CONTENT_MODE_PARAMETER_KEY

        public static final String URL_CONTENT_MODE_PARAMETER_KEY
        This magic parameter is a work-around to the loading indicator becoming "stuck" in certain browsers. It is also used by the static resource handler to set the correct headers
        See Also:
        Constant Field Values
    • Constructor Detail

      • WContent

        public WContent()
    • Method Detail

      • setContentAccess

        public void setContentAccess​(ContentAccess contentAccess)
        Supply this component with access to the document content to be displayed.
        Parameters:
        contentAccess - the ContentAccess which will supply the content.
      • getContentAccess

        public ContentAccess getContentAccess()
        Returns:
        the ContentAccess which will supply the content.
      • display

        public void display()
        Next time this component is painted, it will output the appropriate script to open a new browser window to display the content.
      • getHeight

        public String getHeight()
        Returns:
        The height of the window containing the document content. Default is 600px.
      • setHeight

        public void setHeight​(String height)
        Parameters:
        height - The height of the window containing the document content.
      • isResizable

        public boolean isResizable()
        Returns:
        Returns True if the window is resizable.
      • setResizable

        public void setResizable​(boolean resizable)
        Parameters:
        resizable - Should the window be resizable.
      • getWidth

        public String getWidth()
        Returns:
        The width of the window containing the document content. Default is 800px.
      • setWidth

        public void setWidth​(String width)
        Parameters:
        width - The width of the window containing the document content.
      • getCacheKey

        public String getCacheKey()
        Returns:
        the cacheKey
      • setCacheKey

        public void setCacheKey​(String cacheKey)
        Parameters:
        cacheKey - the cacheKey to set.
      • isDisplayRequested

        public boolean isDisplayRequested()
        Indicates whether the content should be displayed in the given context.
        Returns:
        true if the content should be displayed, otherwise false.
      • getTargetId

        public String getTargetId()
        Implementation of the Targetable interface.
        Specified by:
        getTargetId in interface Targetable
        Returns:
        the target id for this targetable.
      • getUrl

        public String getUrl()
        Retrieves a dynamic URL which this targetable component can be accessed from.
        Returns:
        the URL to access this targetable component.
      • handleRequest

        public void handleRequest​(Request request)

        Override handleRequest in order to perform processing specific to this component.

        When the new browser window for the document content is opened, it will make another request to fetch the content. It is that situation we are trying to detect and handle here.

        Specified by:
        handleRequest in interface WComponent
        Overrides:
        handleRequest in class AbstractWComponent
        Parameters:
        request - the request being responded to.
      • afterPaint

        protected void afterPaint​(RenderContext renderContext)
        Subclasses may override this method to output content after the component has been painted. When overriding this method, it is good practice to call the superclass implementation before emitting any additional content.
        Overrides:
        afterPaint in class AbstractWComponent
        Parameters:
        renderContext - the context to render to.
      • toString

        public String toString()
        Description copied from class: AbstractWComponent
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractWComponent
        Returns:
        a String representation of this component, for debugging purposes.
      • getComponentModel

        protected WContent.ContentModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class AbstractWComponent
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected WContent.ContentModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractWComponent
        Returns:
        the model for this component