Package org.shredzone.commons.view
Interface ViewContext
-
- All Known Implementing Classes:
ViewContextImpl
@ParametersAreNonnullByDefault public interface ViewContext
Provides a context of the View that is to be rendered in this request.A
ViewContext
is request scoped and only valid in threads that ranViewService.handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
.- Author:
- Richard "Shred" Körber
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getParameter(String name)
Gets a parameter from the request URL's search part.Map<String,String>
getPathParts()
Gets a map of all path parts.String
getQualifier()
Gets a View qualifier.String
getRequestServerUrl()
Returns the server URL the request was sent to.String
getRequestServletName()
Returns the name of the servlet that processed the request.<T> T
getValueOfType(Class<T> type)
Gets a value that matches the requested type.<T> void
putTypedArgument(Class<T> type, T value)
Adds a typed argument to this context.void
setPathParts(Map<String,String> pathParts)
Sets the path parts from resolving the view URL.void
setQualifier(String qualifier)
Sets a View qualifier.
-
-
-
Method Detail
-
getRequestServerUrl
@Nonnull String getRequestServerUrl()
Returns the server URL the request was sent to. The URL contains the protocol, the domain and (optionally) the port.- Returns:
- the server URL (e.g. "http://www.shredzone.de")
-
getRequestServletName
@Nonnull String getRequestServletName()
Returns the name of the servlet that processed the request.- Returns:
- the servlet name (e.g. "/cilla")
-
putTypedArgument
<T> void putTypedArgument(Class<T> type, @Nullable T value)
Adds a typed argument to this context. Typed arguments are available to the view handler's parameter list.- Parameters:
type
- Type this argument is to be registered with (may be the value's type or a supertype)value
- the value to register, may benull
-
getValueOfType
<T> T getValueOfType(@Nullable Class<T> type) throws ViewContextException
Gets a value that matches the requested type.- Type Parameters:
T
- the requested type- Parameters:
type
- type to get a value for- Returns:
- a value for that type, may be
null
if the type's value was set tonull
. - Throws:
ViewContextException
- if there was no data satisfying that type
-
setPathParts
void setPathParts(Map<String,String> pathParts)
Sets the path parts from resolving the view URL. Should only be invoked from theViewService
.- Parameters:
pathParts
- Map of path parts
-
getPathParts
@Nonnull Map<String,String> getPathParts()
Gets a map of all path parts. This map is immutable.- Returns:
- Map of path parts
-
getParameter
String getParameter(String name)
Gets a parameter from the request URL's search part.- Parameters:
name
- the parameter name- Returns:
- parameter value, or
null
if there is no such parameter
-
setQualifier
void setQualifier(@Nullable String qualifier)
Sets a View qualifier.- Parameters:
qualifier
- qualifier to be used, ornull
for the standard qualifier
-
getQualifier
String getQualifier()
Gets a View qualifier.- Returns:
- qualifier to be used, or
null
for the standard qualifier
-
-