Class JspContext


  • public class JspContext
    extends ClientContext
    Context object for the web application. Instances of this class are always used for passing client context information to web extensions. This means that it is always safe to cast the client context to this class in the ActionFactory.prepareContext(InvokationContext) and ActionFactory.getActions(InvokationContext) methods and other methods that has a context parameter.
    @Override
    public boolean prepareContext(InvokationContext context) 
    {
            JspContext jspContext = (JspContext)context.getClientContext();
            jspContext.addStylesheet("/base/include/styles/mystylesheet.css");
            // Do other things
            return true;
    }
    

    This context exposes the underlying JSP PageContext, which can be used to get information about the current request among other things. Render factories usually needs access to the response output stream, getOut(), so that renderers can write the generated HTML to the response.

    Version:
    2.7
    Author:
    nicklas
    Last modified
    $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
    • Field Detail

      • ATTRIBUTE_KEY

        public static final String ATTRIBUTE_KEY
        The key that is used when storing a JspContext object in a request/page/session/etc. attribute.
        Since:
        2.17
        See Also:
        Constant Field Values
      • EXTENSION_KEY

        public static final String EXTENSION_KEY
        The key that is used when storing an Extension object in a request/page/session/etc. attribute.
        Since:
        3.3
        See Also:
        Constant Field Values
      • stylesheets

        private Set<String> stylesheets
    • Method Detail

      • getPageContext

        public PageContext getPageContext()
        Get the JSP Page context object for the current request.
      • getGuiContext

        public GuiContext getGuiContext()
        Get the current GuiContext.
        Returns:
        A GuiContext object or null if it is not applicable to the extension point
        Since:
        2.12
      • getRoot

        public String getRoot()
        Get the URL to the web application root as a string. The URL only includes the path information, not the server name or protocol.
      • getHome

        public String getHome​(Extension<?> extension)
        Get the URL to the home directory for a given extension. The URL only includes the path information, not the server name or protocol.
        Parameters:
        extension - The extension
      • addScript

        public void addScript​(String absolutePath)
        Add an absolute reference to a script that should be included on the generated page with a <script> tag. The path must be an absolute path.

        Note 1! This method must be called from the ActionFactory.prepareContext(InvokationContext) or RendererFactory.prepareContext(InvokationContext) methods. Changes to the context after that will not be reflected in the output.

        Note 2! Not all extension points supports custom scripts. Check the documentation for the extension point you are extending.

        Parameters:
        absolutePath - The absolute path
      • addStylesheet

        public void addStylesheet​(String absolutePath)
        Add an absolute reference to a CSS stylesheet that should be included on the generated page with a <link> tag. The path must be the absolute path.

        Note 1! This method must be called from the ActionFactory.prepareContext(InvokationContext) or RendererFactory.prepareContext(InvokationContext) methods. Changes to the context after that will not be reflected in the output.

        Note 2! Not all extension points supports custom stylesheets. Check the documentation for the extension point you are extending.

        Parameters:
        absolutePath - The absolute path
      • getScripts

        public Collection<String> getScripts()
        Get all scripts that has been added to this context.
        Returns:
        A collection of scripts
      • getStylesheets

        public Collection<String> getStylesheets()
        Get all stylesheets that has been added to this context.
        Returns:
        A collection of stylesheets