Class BeanNameViewResolver

java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.BeanNameViewResolver
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.web.context.ServletContextAware, ViewResolver

public class BeanNameViewResolver extends org.springframework.web.context.support.WebApplicationObjectSupport implements ViewResolver, org.springframework.core.Ordered
A simple implementation of ViewResolver that interprets a view name as a bean name in the current application context, i.e. typically in the XML file of the executing DispatcherServlet or in a corresponding configuration class.

Note: This ViewResolver implements the Ordered interface in order to allow for flexible participation in ViewResolver chaining. For example, some special views could be defined via this ViewResolver (giving it 0 as "order" value), while all remaining views could be resolved by a UrlBasedViewResolver.

Since:
18.06.2003
Author:
Juergen Hoeller
See Also:
  • Field Summary

    Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

    logger

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    resolveViewName(String viewName, Locale locale)
    Resolve the given view by name.
    void
    setOrder(int order)
    Specify the order value for this ViewResolver bean.

    Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

    getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext

    Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

    getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BeanNameViewResolver

      public BeanNameViewResolver()
  • Method Details

    • setOrder

      public void setOrder(int order)
      Specify the order value for this ViewResolver bean.

      The default value is Ordered.LOWEST_PRECEDENCE, meaning non-ordered.

      See Also:
      • Ordered.getOrder()
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • resolveViewName

      @Nullable public View resolveViewName(String viewName, Locale locale) throws org.springframework.beans.BeansException
      Description copied from interface: ViewResolver
      Resolve the given view by name.

      Note: To allow for ViewResolver chaining, a ViewResolver should return null if a view with the given name is not defined in it. However, this is not required: Some ViewResolvers will always attempt to build View objects with the given name, unable to return null (rather throwing an exception when View creation failed).

      Specified by:
      resolveViewName in interface ViewResolver
      Parameters:
      viewName - name of the view to resolve
      locale - the Locale in which to resolve the view. ViewResolvers that support internationalization should respect this.
      Returns:
      the View object, or null if not found (optional, to allow for ViewResolver chaining)
      Throws:
      org.springframework.beans.BeansException