Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need some explanation about BeanNameViewResolver

i read the documentation here: http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/servlet/view/BeanNameViewResolver.html

but i think that the spring documentation sometimes can become complex and hard to understand, so i need little explanation about this class.

like image 630
Mahmoud Saleh Avatar asked Sep 12 '11 16:09

Mahmoud Saleh


1 Answers

As described in the documentation, BeanNameViewResolver resolves Views declared as beans. Usually you need it for some special-purpose views.

Imagine, for example, that one of your controllers should render an Excel spreadsheet. So, you subclass AbstractExcelView and implement your custom logic to render a spreadsheet based on model values:

public class MyExcelView extends AbstractExcelView { ... }

and declare it as a bean:

<bean id = "myExcelView" class = "MyExcelView" />

Then declaring an BeanNameViewResolver makes it available to controllers: when controller returns ModelAndView with view name myExcelView, your spreadsheet will be rendered.

BeanNameViewResolver is usually used in conjunction with some other view resolver that handles "regular" views (so that if BeanNameViewResolver can't find a view, the other resolver tries to find it):

<bean class = "...BeanNameViewResolver">
    <property name = "order" value = "0" />
</bean>

<bean class = "...InternalResourceViewResolver">
    <property name = "order" value = "1" />
    ...
</bean>
like image 181
axtavt Avatar answered Sep 18 '22 20:09

axtavt