Class ExternalContextUtils


  • public final class ExternalContextUtils
    extends Object
    This provides some functionality for determining some things about the native request object that is not provided by Faces. This class is useful for use in places where Portlet API's may or may not be present and can also provide access to some request-specific items which are not available on the Faces ExternalContext. If portlet API's are not present, this class simply handles the Servlet Request type.
    • Method Detail

      • isPortlet

        public static boolean isPortlet​(ExternalContext ec)
        This is a convenience function designed to perform a quick check of the current ExternalContext.
        Parameters:
        ec - the current external context
        Returns:
        true if the current ExternalContext is a Porlet.
      • isHttpServletRequest

        public static boolean isHttpServletRequest​(ExternalContext ec)
        Returns wherther of not this external context represents a true HttpServletRequest or not. Some portal containers implement the PortletRequest/Response objects as HttpServletRequestWrappers, and those objects should not be treated as an HttpServlerRequest. As such, this method first tests to see if the request is a portlet request and, if not, then tests to see if the request is an instanceof HttpServletRequest.
        Parameters:
        ec - the current external context
        Returns:
        a boolean value of true if the current request is an HttpServletRequest
      • getHttpServletResponse

        public static jakarta.servlet.http.HttpServletResponse getHttpServletResponse​(ExternalContext ec)
        Returns an HttpServletResponse if one exists on the externalContext or null if it does not. Please note that some portal environments implement the PortletRequest and Response objects as HttpServletRequest/Response objects. This method handles these types of requests properly and will therefore return null in portal environments.
        Parameters:
        ec -
        Returns:
        an HttpServletResponse if we have one or null if we do not
      • getHttpServletRequest

        public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest​(ExternalContext ec)
        Returns an HttpServletRequest if one exists on the externalContext or null if it does not. Please note that some portal environments implement the PortletRequest and Response objects as HttpServletRequest/Response objects. This method handles these types of requests properly and will therefore return null in portal environments.
        Parameters:
        ec -
        Returns:
        an HttpServletResponse if we have one or null if we do not
      • getHttpServletResponse

        public static jakarta.servlet.http.HttpServletResponse getHttpServletResponse​(Object response)
        Trys to obtain a HttpServletResponse from the Response. Note that this method also trys to unwrap any ServletResponseWrapper in order to retrieve a valid HttpServletResponse.
        Parameters:
        response -
        Returns:
        if found, the HttpServletResponse, null otherwise