|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractCachingViewResolver
org.springframework.web.servlet.view.UrlBasedViewResolver
Simple implementation of ViewResolver that allows for direct resolution of symbolic view names to URLs, without explicit mapping definition. This is appropriate if your symbolic names match the names of your view resources in a straightforward manner, without the need for arbitrary mappings.
Supports AbstractUrlBasedView subclasses like InternalResourceView, VelocityView and FreeMarkerView. The view class for all views generated by this resolver can be specified via the "viewClass" property.
View names can either be resource URLs themselves, or get augmented by a specified prefix and/or suffix. Exporting an attribute that holds the RequestContext to all views is explicitly supported.
Example: prefix="/WEB-INF/jsp/", suffix=".jsp", viewname="test" -> "/WEB-INF/jsp/test.jsp"
As a special feature, redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction.do" will trigger a redirect to the given URL, rather than resolution as standard view name.
Note: This class does not support localized resolution, i.e. resolving a symbolic view name to different resources depending on the current locale.
Note: When chaining ViewResolvers, a UrlBasedViewResolver always needs to be last, as it will attempt to resolve any view name, no matter whether the underlying resource actually exists.
setViewClass(java.lang.Class)
,
setPrefix(java.lang.String)
,
setSuffix(java.lang.String)
,
setRequestContextAttribute(java.lang.String)
,
REDIRECT_URL_PREFIX
,
AbstractUrlBasedView
,
InternalResourceView
,
VelocityView
,
FreeMarkerView
Field Summary | |
static String |
REDIRECT_URL_PREFIX
|
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
logger |
Constructor Summary | |
UrlBasedViewResolver()
|
Method Summary | |
protected View |
createView(String viewName,
Locale locale)
Overridden to implement check for "redirect:" prefix. |
protected String |
getCacheKey(String viewName,
Locale locale)
This implementation returns just the view name, as this ViewResolver doesn't support localized resolution. |
protected void |
initApplicationContext()
Subclasses can override this for custom initialization behavior. |
protected View |
loadView(String viewName,
Locale locale)
Creates a new instance of the specified view class and configures it. |
protected Class |
requiredViewClass()
Return the required type of view for this resolver. |
void |
setContentType(String contentType)
Set the content type for all views. |
void |
setPrefix(String prefix)
Set the prefix that gets applied to view names when building a URL. |
void |
setRedirectContextRelative(boolean redirectContextRelative)
Set whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. |
void |
setRedirectHttp10Compatible(boolean redirectHttp10Compatible)
Set whether redirects should stay compatible with HTTP 1.0 clients. |
void |
setRequestContextAttribute(String requestContextAttribute)
Set the name of the RequestContext attribute for all views. |
void |
setSuffix(String suffix)
Set the suffix that gets applied to view names when building a URL. |
void |
setViewClass(Class viewClass)
Set the view class that should be used to create views. |
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver |
isCache, removeFromCache, resolveViewName, setCache |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
getServletContext, getTempDir, getWebApplicationContext |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String REDIRECT_URL_PREFIX
Constructor Detail |
public UrlBasedViewResolver()
Method Detail |
public void setViewClass(Class viewClass)
viewClass
- class that is assignable to the required view class
(by default, AbstractUrlBasedView)AbstractUrlBasedView
protected Class requiredViewClass()
AbstractUrlBasedView
public void setPrefix(String prefix)
prefix
- view name prefixpublic void setSuffix(String suffix)
suffix
- view name suffixpublic void setContentType(String contentType)
contentType
- the content typepublic void setRequestContextAttribute(String requestContextAttribute)
requestContextAttribute
- name of the RequestContext attributeAbstractView.setRequestContextAttribute(java.lang.String)
public void setRedirectContextRelative(boolean redirectContextRelative)
Default is true: A redirect URL that starts with a slash will be interpreted as relative to the web application root, i.e. the context path will be prepended to the URL.
Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction.do"
RedirectView.setContextRelative(boolean)
,
REDIRECT_URL_PREFIX
public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible)
In the default implementation, this will enforce HTTP status code 302
in any case, i.e. delegate to HttpServletResponse.sendRedirect
.
Turning this off will send HTTP status code 303, which is the correct
code for HTTP 1.1 clients, but not understood by HTTP 1.0 clients.
Many HTTP 1.1 clients treat 302 just like 303, not making any difference. However, some clients depend on 303 when redirecting after a POST request; turn this flag off in such a scenario.
Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction.do"
RedirectView.setHttp10Compatible(boolean)
,
REDIRECT_URL_PREFIX
protected void initApplicationContext()
ApplicationObjectSupport
Note: Does not get called on reinitialization of the context.
initApplicationContext
in class ApplicationObjectSupport
protected String getCacheKey(String viewName, Locale locale)
getCacheKey
in class AbstractCachingViewResolver
protected View createView(String viewName, Locale locale) throws Exception
Not possible in loadView, as overridden loadView versions in subclasses might rely on the superclass always creating instances of the required view class.
createView
in class AbstractCachingViewResolver
viewName
- the name of the view to retrievelocale
- the Locale to retrieve the view for
Exception
- if the view couldn't be resolvedloadView(java.lang.String, java.util.Locale)
,
requiredViewClass()
protected View loadView(String viewName, Locale locale) throws BeansException
loadView
in class AbstractCachingViewResolver
viewName
- the name of the view to retrievelocale
- the Locale to retrieve the view for
BeansException
AbstractCachingViewResolver.resolveViewName(java.lang.String, java.util.Locale)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |