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:
Aware,ApplicationContextAware,Ordered,ServletContextAware,ViewResolver
public class BeanNameViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered
A simple implementation ofViewResolverthat interprets a view name as a bean name in the current application context, i.e. typically in the XML file of the executingDispatcherServlet.This resolver can be handy for small applications, keeping all definitions ranging from controllers to views in the same place. For larger applications,
XmlViewResolverwill be the better choice, as it separates the XML view bean definitions into a dedicated views file.Note: Neither this
ViewResolvernorXmlViewResolversupports internationalization. ConsiderResourceBundleViewResolverif you need to apply different view resources per locale.Note: This
ViewResolverimplements theOrderedinterface in order to allow for flexible participation inViewResolverchaining. For example, some special views could be defined via thisViewResolver(giving it 0 as "order" value), while all remaining views could be resolved by aUrlBasedViewResolver.- 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
Constructors Constructor Description BeanNameViewResolver()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetOrder()Get the order value of this object.ViewresolveViewName(String viewName, Locale locale)Resolve the given view by name.voidsetOrder(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, requiredContextClass, setApplicationContext
Constructor Detail
BeanNameViewResolver
public BeanNameViewResolver()
Method Detail
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()
Description copied from interface:OrderedGet the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet
load-on-startupvalues).Same order values will result in arbitrary sort positions for the affected objects.
- Specified by:
getOrderin interfaceOrdered- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE,Ordered.LOWEST_PRECEDENCE
resolveViewName
public View resolveViewName(String viewName, Locale locale) throws BeansException
Description copied from interface:ViewResolverResolve the given view by name.Note: To allow for ViewResolver chaining, a ViewResolver should return
nullif 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 returnnull(rather throwing an exception when View creation failed).- Specified by:
resolveViewNamein interfaceViewResolver- Parameters:
viewName- name of the view to resolvelocale- Locale in which to resolve the view. ViewResolvers that support internationalization should respect this.- Returns:
- the View object, or
nullif not found (optional, to allow for ViewResolver chaining) - Throws:
BeansException