org.springframework.web.servlet.view
Class UrlBasedViewResolver

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.view.AbstractCachingViewResolver
              extended byorg.springframework.web.servlet.view.UrlBasedViewResolver
All Implemented Interfaces:
ApplicationContextAware, ViewResolver
Direct Known Subclasses:
InternalResourceViewResolver, VelocityViewResolver

public class UrlBasedViewResolver
extends AbstractCachingViewResolver

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 and VelocityView. The view class for all views generated by this resolver can be specified via setViewClass.

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"

Note: This class does not support localized resolution, i.e. resolving a symbolic view name to different resources depending on the current locale.

Since:
13.12.2003
Author:
Juergen Hoeller
See Also:
setViewClass(java.lang.Class), setPrefix(java.lang.String), setSuffix(java.lang.String), setRequestContextAttribute(java.lang.String), AbstractUrlBasedView

Field Summary
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
UrlBasedViewResolver()
           
 
Method Summary
protected  java.lang.String getCacheKey(java.lang.String viewName, java.util.Locale locale)
          This implementation returns just the view name, as InternalResourceViewResolver doesn't support localized resolution.
protected  View loadView(java.lang.String viewName, java.util.Locale locale)
          Subclasses must implement this method.
protected  java.lang.Class requiredViewClass()
          Return the required type of view for this resolver.
 void setContentType(java.lang.String contentType)
          Set the content type for all views.
 void setPrefix(java.lang.String prefix)
          Set the prefix that gets applied to view names when building a URL.
 void setRequestContextAttribute(java.lang.String requestContextAttribute)
          Set the name of the RequestContext attribute for all views.
 void setSuffix(java.lang.String suffix)
          Set the suffix that gets applied to view names when building a URL.
 void setViewClass(java.lang.Class viewClass)
          Set the view class that should be used to create views.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
isCache, resolveViewName, setCache
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, requiredContextClass
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlBasedViewResolver

public UrlBasedViewResolver()
Method Detail

setViewClass

public void setViewClass(java.lang.Class viewClass)
Set the view class that should be used to create views.

Parameters:
viewClass - class that is assignable to InternalResourceView

requiredViewClass

protected java.lang.Class requiredViewClass()
Return the required type of view for this resolver. This implementation returns AbstractUrlBasedView.

See Also:
AbstractUrlBasedView

setPrefix

public void setPrefix(java.lang.String prefix)
Set the prefix that gets applied to view names when building a URL.

Parameters:
prefix - view name prefix

setSuffix

public void setSuffix(java.lang.String suffix)
Set the suffix that gets applied to view names when building a URL.

Parameters:
suffix - view name suffix

setContentType

public void setContentType(java.lang.String contentType)
Set the content type for all views. May be ignored by view classes if the view itself is assumed to set the content type, e.g. in case of JSPs.

Parameters:
contentType - the content type

setRequestContextAttribute

public void setRequestContextAttribute(java.lang.String requestContextAttribute)
Set the name of the RequestContext attribute for all views.

Parameters:
requestContextAttribute - name of the RequestContext attribute

getCacheKey

protected java.lang.String getCacheKey(java.lang.String viewName,
                                       java.util.Locale locale)
This implementation returns just the view name, as InternalResourceViewResolver doesn't support localized resolution.

Overrides:
getCacheKey in class AbstractCachingViewResolver

loadView

protected View loadView(java.lang.String viewName,
                        java.util.Locale locale)
Description copied from class: AbstractCachingViewResolver
Subclasses must implement this method. There need be no concern for efficiency, as this class will cache views. Not all subclasses may support internationalization: A subclass that doesn't can simply ignore the locale parameter.

Specified by:
loadView in class AbstractCachingViewResolver
Parameters:
viewName - the name of the view to retrieve
locale - the Locale to retrieve the view for
Returns:
the View instance


Copyright (C) 2003-2004 The Spring Framework Project.