com.interface21.web.servlet.view
Class InternalResourceViewResolver

java.lang.Object
  |
  +--com.interface21.context.support.ApplicationObjectSupport
        |
        +--com.interface21.web.servlet.view.AbstractCachingViewResolver
              |
              +--com.interface21.web.servlet.view.InternalResourceViewResolver
All Implemented Interfaces:
ApplicationContextAware, ViewResolver

public class InternalResourceViewResolver
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 InternalResourceView (i.e. Servlets and JSPs), and subclasses like JstlView. 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"

BTW, it's good practice to put JSP files that just serve as views under WEB-INF, to hide them from direct access (e.g. via a manually entered URL). Only controllers will be able to access them then.

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

Since:
17.02.2003
Author:
Juergen Hoeller
See Also:
setViewClass(java.lang.Class), setPrefix(java.lang.String), setSuffix(java.lang.String), setRequestContextAttribute(java.lang.String), InternalResourceView, JstlView

Fields inherited from class com.interface21.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
InternalResourceViewResolver()
           
 
Method Summary
protected  View loadView(java.lang.String viewName, java.util.Locale locale)
          Subclasses must implement this method.
 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, or null if not needed.
 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 com.interface21.web.servlet.view.AbstractCachingViewResolver
isCache, resolveViewName, setCache
 
Methods inherited from class com.interface21.context.support.ApplicationObjectSupport
getApplicationContext, initApplicationContext, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.interface21.context.ApplicationContextAware
setApplicationContext
 

Constructor Detail

InternalResourceViewResolver

public InternalResourceViewResolver()
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

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

setRequestContextAttribute

public void setRequestContextAttribute(java.lang.String requestContextAttribute)
Set the name of the RequestContext attribute for all views, or null if not needed.
Parameters:
requestContextAttribute - name of the RequestContext attribute

loadView

protected View loadView(java.lang.String viewName,
                        java.util.Locale locale)
                 throws javax.servlet.ServletException
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 ignore the locale parameter.
Overrides:
loadView in class AbstractCachingViewResolver
Following copied from class: com.interface21.web.servlet.view.AbstractCachingViewResolver
Parameters:
viewName - name of the view to retrieve
locale - Locale to retrieve the view for
Returns:
the View if it can be resolved, or null
Throws:
javax.servlet.ServletException - if there is an error trying to resolve the view


Rod Johnson and Spring contributors 2001-2003.