Class AttributeHelper

  • All Implemented Interfaces:
    UseWithRenderContext

    public class AttributeHelper
    extends Object
    implements UseWithRenderContext
    Allows setting and reading request-/session-attributes, script bindings or a simulated pageContext (EmulatedPageContext). If there should be something written, the parameter scope should be one of bindings, page, request, session (page being the EmulatedPageContext), and there can be a key and value parameter to set one value, or an arbitrary number key1, key2, key3 ... and corresponding value1, value2, value3, ... parameters to set the values in that scope.
    Since:
    09/2017
    Author:
    Hans-Peter Stoerr
    • Constructor Detail

      • AttributeHelper

        public AttributeHelper()
    • Method Detail

      • init

        public void init​(org.apache.sling.scripting.sightly.render.RenderContext renderContext,
                         Bindings arguments)
        Description copied from interface: UseWithRenderContext

        Called to initialize the Java object with the current Java Scripting API arguments.

        This method is called only if the object has been instantiated by HTL as part of processing the data-sly-use attribute. The Java Scripting API arguments provide all the global variables known to a script being executed.

        Specified by:
        init in interface UseWithRenderContext
        Parameters:
        renderContext - the context where this is called. Caution: modifying RenderContext.getBindings() will change the global bindings.
        arguments - The Java Scripting API arguments. Caution: modifying this could interfere with other providers.
      • getRequest

        protected org.apache.sling.api.SlingHttpServletRequest getRequest()
      • getRequestParameters

        public Map<String,​String[]> getRequestParameters()
        The map of request parameters. Caution: the values are arrays.
      • getRequestAttributes

        public org.apache.sling.scripting.sightly.Record<Object> getRequestAttributes()
        Provides a HTL readable view of the request attributes.
      • getSessionAttributes

        public org.apache.sling.scripting.sightly.Record<Object> getSessionAttributes()
        Provides a HTL readable view of the session Attributes.
      • getBindings

        public Bindings getBindings()
        Provides a HTL readable view of the Bindings.