Top Description Inners Fields Constructors Methods
org.springframework.web.context.request

public abstract Class RequestContextHolder

extends Object
Class Inheritance
Imports
jakarta.faces.context.FacesContext, org.springframework.core.NamedInheritableThreadLocal, .NamedThreadLocal, org.springframework.lang.Nullable, org.springframework.util.ClassUtils

Holder class to expose the web request in the form of a thread-bound RequestAttributes object. The request will be inherited by any child threads spawned by the current thread if the inheritable flag is set to true.

Use RequestContextListener or org.springframework.web.filter.RequestContextFilter to expose the current web request. Note that org.springframework.web.servlet.DispatcherServlet already exposes the current request by default.

Authors
Juergen Hoeller, Rod Johnson
Since
2.0
See Also
RequestContextListener, org.springframework.web.filter.RequestContextFilter, org.springframework.web.servlet.DispatcherServlet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
RequestContextHolder.FacesRequestAttributesFactory

Inner class to avoid hard-coded JSF dependency.

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<RequestAttributes>
private static final boolean
private static final ThreadLocal<RequestAttributes>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static RequestAttributes

Returns:

the RequestAttributes currently bound to the thread
currentRequestAttributes
()

Return the RequestAttributes currently bound to the thread.

public static RequestAttributes

Returns:

the RequestAttributes currently bound to the thread, or null if none bound
getRequestAttributes
()

Return the RequestAttributes currently bound to the thread.

public static void
resetRequestAttributes()

Reset the RequestAttributes for the current thread.

public static void
setRequestAttributes(RequestAttributes
the RequestAttributes to expose
attributes
)

Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.

public static void
setRequestAttributes(RequestAttributes
the RequestAttributes to expose, or null to reset the thread-bound context
attributes
,
boolean
whether to expose the RequestAttributes as inheritable for child threads (using an InheritableThreadLocal)
inheritable
)

Bind the given RequestAttributes to the current thread.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inheritableRequestAttributesHolderback to summary
private static final ThreadLocal<RequestAttributes> inheritableRequestAttributesHolder
jsfPresentback to summary
private static final boolean jsfPresent
requestAttributesHolderback to summary
private static final ThreadLocal<RequestAttributes> requestAttributesHolder

Constructor Detail

RequestContextHolderback to summary
public RequestContextHolder()

Method Detail

currentRequestAttributesback to summary
public static RequestAttributes currentRequestAttributes() throws IllegalStateException

Return the RequestAttributes currently bound to the thread.

Exposes the previously bound RequestAttributes instance, if any. Falls back to the current JSF FacesContext, if any.

Returns:RequestAttributes

the RequestAttributes currently bound to the thread

Exceptions
IllegalStateException:
if no RequestAttributes object is bound to the current thread
See Also
setRequestAttributes, ServletRequestAttributes, FacesRequestAttributes, jakarta.faces.context.FacesContext#getCurrentInstance()
getRequestAttributesback to summary
public static RequestAttributes getRequestAttributes()

Return the RequestAttributes currently bound to the thread.

Returns:RequestAttributes

the RequestAttributes currently bound to the thread, or null if none bound

Annotations
@Nullable
resetRequestAttributesback to summary
public static void resetRequestAttributes()

Reset the RequestAttributes for the current thread.

setRequestAttributesback to summary
public static void setRequestAttributes(RequestAttributes attributes)

Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.

Parameters
attributes:RequestAttributes

the RequestAttributes to expose

See Also
setRequestAttributes(RequestAttributes, boolean)
setRequestAttributesback to summary
public static void setRequestAttributes(RequestAttributes attributes, boolean inheritable)

Bind the given RequestAttributes to the current thread.

Parameters
attributes:RequestAttributes

the RequestAttributes to expose, or null to reset the thread-bound context

inheritable:boolean

whether to expose the RequestAttributes as inheritable for child threads (using an InheritableThreadLocal)

org.springframework.web.context.request back to summary

private Class RequestContextHolder.FacesRequestAttributesFactory

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.context.request.RequestContextHolder.FacesRequestAttributesFactory

Inner class to avoid hard-coded JSF dependency.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static RequestAttributes
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FacesRequestAttributesFactoryback to summary
private FacesRequestAttributesFactory()

Method Detail

getFacesRequestAttributesback to summary
public static RequestAttributes getFacesRequestAttributes()
Annotations
@Nullable