Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

View Resolving through ViewResolver interface

In this section, you will learn about resolving view through ViewResolver interface.

Ads

Tutorials   
Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller
Ads

View Resolving through ViewResolver interface

In this section, you will learn about resolving view through ViewResolver interface.

In Spring, two Interfaces View and ViewResolver  plays a very important role in handling views. The ViewResolver provides mapping between view and actual views. The request preparation is handled by the View Interface and it also passes the request to one of the view technologies.

Spring Web MVC controllers resolves logical view name either explicitly (e.g., by returning a String, View, or ModelAndView) or implicitly (i.e., based on conventions). In Spring, 'logical view name' represents Views and it is resolved by a view resolver. There are a few view resolver in Spring. Given below the list of view resolvers in Spring :

ViewResolver Description
AbstractCachingViewResolver This view resolver caches views.
XmlViewResolver This view resolver uses configuration file written in XML for view resolution.
ResourceBundleViewResolver This view resolver uses ResourceBundle , represented by the bundle base name, to resolve view. Generally bundle is defined in a properties file, situated in the classpath.
UrlBasedViewResolver This view resolver uses 'logical view name' returned to find the actual view.
InternalResourceViewResolver This view resolver is the subclass of UrlBasedViewResolver and also supports InternalResourceView(practically Servlets and JSPs) and also subclasses such as JstlView and TilesView.
VelocityViewResolver / FreeMarkerViewResolver This view resolver is the subclass of UrlBasedViewResolver which supports VelocityView, FreeMarkerView and its custom subclasses.
ContentNegotiatingViewResolver This view resolver is the implementation of the ViewResolver interface which resolves view on the basis of request file name or Accept header.

Some Example Configurations

Configuration for UrlBasedViewResolver :

<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
	<property name="prefix" value="/WEB-INF/jsp/"/>
	<property name="suffix" value=".jsp"/>
</bean>

The view resolver adds the prefix and suffix to the returned "logical view name" to find the actual view. For example, if loginpage is returned then the actual view will be /WEB-INF/jsp/loginpage.jsp.

Configuration for ResourceBundleViewResolver :

<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
	<property name="basename" value="views"/>
	<property name="defaultParentView" value="parentView"/>
</bean>

The ResourceBundle represented by the basename is inspected by the ResourceBundleViewResolver to resolve view and each view it is supposed to resolve, it uses the value of the property [viewname].(class) as the view class and the value of the property [viewname].url as the view url.



Advertisements

Share on Google+Share on Google+

View Resolving through ViewResolver interface

Posted on: January 9, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: View Resolving through ViewResolver interface  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads