XML Marshalling View Tiles

4.3.9.RELEASE Spring Framework 586 polyfill.js only defines the window object needed by Handlebars to run properly: var window = {}; This basic render.js implementation compiles the template before using it. A production ready implementation should also store and reused cached templates pre-compiled templates. This can be done on the script side, as well as any customization you need managing template engine configuration for example. function rendertemplate, model { var compiledTemplate = Handlebars.compiletemplate; return compiledTemplatemodel; } Check out Spring script templates unit tests java , resources for more configuration examples.

23.7 XML Marshalling View

The MarshallingView uses an XML Marshaller defined in the org.springframework.oxm package to render the response content as XML. The object to be marshalled can be set explicitly using MarhsallingView’s `modelKey bean property. Alternatively, the view will iterate over all model properties and marshal the first type that is supported by the Marshaller . For more information on the functionality in the org.springframework.oxm package refer to the chapter Marshalling XML using OX Mappers .

23.8 Tiles

It is possible to integrate Tiles - just as any other view technology - in web applications using Spring. The following describes in a broad way how to do this. Note This section focuses on Spring’s support for Tiles v3 in the org.springframework.web.servlet.view.tiles3 package. Dependencies To be able to use Tiles, you have to add a dependency on Tiles version 3.0.1 or higher and its transitive dependencies to your project. How to integrate Tiles To be able to use Tiles, you have to configure it using files containing definitions for basic information on definitions and other Tiles concepts, please have a look at http:tiles.apache.org . In Spring this is done using the TilesConfigurer . Have a look at the following piece of example ApplicationContext configuration: 4.3.9.RELEASE Spring Framework 587 bean id = tilesConfigurer class = org.springframework.web.servlet.view.tiles3.TilesConfigurer property name = definitions list value WEB-INFdefsgeneral.xml value value WEB-INFdefswidgets.xml value value WEB-INFdefsadministrator.xml value value WEB-INFdefscustomer.xml value value WEB-INFdefstemplates.xml value list property bean As you can see, there are five files containing definitions, which are all located in the WEB-INF defs directory. At initialization of the WebApplicationContext , the files will be loaded and the definitions factory will be initialized. After that has been done, the Tiles includes in the definition files can be used as views within your Spring web application. To be able to use the views you have to have a ViewResolver just as with any other view technology used with Spring. Below you can find two possibilities, the UrlBasedViewResolver and the ResourceBundleViewResolver . You can specify locale specific Tiles definitions by adding an underscore and then the locale. For example: bean id = tilesConfigurer class = org.springframework.web.servlet.view.tiles3.TilesConfigurer property name = definitions list value WEB-INFdefstiles.xml value value WEB-INFdefstiles_fr_FR.xml value list property bean With this configuration, tiles_fr_FR.xml will be used for requests with the fr_FR locale, and tiles.xml will be used by default. Note Since underscores are used to indicate locales, it is recommended to avoid using them otherwise in the file names for Tiles definitions. UrlBasedViewResolver The UrlBasedViewResolver instantiates the given viewClass for each view it has to resolve. bean id = viewResolver class = org.springframework.web.servlet.view.UrlBasedViewResolver property name = viewClass value = org.springframework.web.servlet.view.tiles3.TilesView bean ResourceBundleViewResolver The ResourceBundleViewResolver has to be provided with a property file containing viewnames and viewclasses the resolver can use: bean id = viewResolver class = org.springframework.web.servlet.view.ResourceBundleViewResolver property name = basename value = views bean 4.3.9.RELEASE Spring Framework 588 ... welcomeView. class =org.springframework.web.servlet.view.tiles3.TilesView welcomeView.url=welcome this is the name of a Tiles definition vetsView. class =org.springframework.web.servlet.view.tiles3.TilesView vetsView.url=vetsView again, this is the name of a Tiles definition findOwnersForm. class =org.springframework.web.servlet.view.JstlView findOwnersForm.url=WEB-INFjspfindOwners.jsp ... As you can see, when using the ResourceBundleViewResolver , you can easily mix different view technologies. Note that the TilesView class supports JSTL the JSP Standard Tag Library out of the box. SimpleSpringPreparerFactory and SpringBeanPreparerFactory As an advanced feature, Spring also supports two special Tiles PreparerFactory implementations. Check out the Tiles documentation for details on how to use ViewPreparer references in your Tiles definition files. Specify SimpleSpringPreparerFactory to autowire ViewPreparer instances based on specified preparer classes, applying Spring’s container callbacks as well as applying configured Spring BeanPostProcessors. If Spring’s context-wide annotation-config has been activated, annotations in ViewPreparer classes will be automatically detected and applied. Note that this expects preparer classes in the Tiles definition files, just like the default PreparerFactory does. Specify SpringBeanPreparerFactory to operate on specified preparer names instead of classes, obtaining the corresponding Spring bean from the DispatcherServlet’s application context. The full bean creation process will be in the control of the Spring application context in this case, allowing for the use of explicit dependency injection configuration, scoped beans etc. Note that you need to define one Spring bean definition per preparer name as used in your Tiles definitions. bean id = tilesConfigurer class = org.springframework.web.servlet.view.tiles3.TilesConfigurer property name = definitions list value WEB-INFdefsgeneral.xml value value WEB-INFdefswidgets.xml value value WEB-INFdefsadministrator.xml value value WEB-INFdefscustomer.xml value value WEB-INFdefstemplates.xml value list property -- resolving preparer names as Spring bean definition names -- property name = preparerFactoryClass value = org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory bean

23.9 XSLT