站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

BeanNameViewResolver (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.web.servlet.view
Class BeanNameViewResolver

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.view.BeanNameViewResolver
All Implemented Interfaces:
ApplicationContextAware, Ordered, ServletContextAware, ViewResolver

public class BeanNameViewResolver
extends WebApplicationObjectSupport
implements ViewResolver, Ordered

Simple implementation of ViewResolver that interprets a view name as bean name in the current application context, i.e. in the XML file of the executing DispatcherServlet.

This resolver can be handy for small applications, keeping all definitions ranging from controllers to views in the same place. For normal applications, XmlViewResolver will be the better choice, as it separates the XML view bean definitions into a dedicated views file. View beans should virtually never have references to any other application beans - such a separation will make this clear.

This ViewResolver does not support internationalization. Conside ResourceBundleViewResolver if you need to apply different view resources per locale.

Note: This ViewResolver implements the Ordered interface 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:
XmlViewResolver, ResourceBundleViewResolver, UrlBasedViewResolver

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
BeanNameViewResolver()
           
 
Method Summary
 int getOrder()
          Return the order value of this object, with a higher value meaning greater in terms of sorting.
 View resolveViewName(String viewName, Locale locale)
          Resolve the given view by name.
 void setOrder(int order)
           
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanNameViewResolver

public BeanNameViewResolver()
Method Detail

setOrder

public void setOrder(int order)

getOrder

public int getOrder()
Description copied from interface: Ordered
Return the order value of this object, with a higher value meaning greater in terms of sorting.

Normally starting with 0 or 1, with Ordered.LOWEST_PRECEDENCE indicating greatest. Same order values will result in arbitrary positions for the affected objects.

Higher value can be interpreted as lower priority, consequently the first object has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Note that order values below 0 are reserved for framework purposes. Application-specified values should always be 0 or greater, with only framework components (internal or third-party) supposed to use lower values.

Specified by:
getOrder in interface Ordered
Returns:
the order value
See Also:
Ordered.LOWEST_PRECEDENCE

resolveViewName

public View resolveViewName(String viewName,
                            Locale locale)
                     throws 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 - 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:
BeansException

The Spring Framework

Copyright © 2002-2007 The Spring Framework.