Pages

Wednesday, August 20, 2014

HowTo:: Spring 4 Scala MVC without Web.XML - Tiles3 : static resources and front-end templating

Img.1.:: project structure - Tiles3 with localised messages and simple template 
This blogpost is fully focused on simple spring 4 scala project Tiles configuration and how to give access to the localised messages (see. Img.1.). 
In the WebConfig scala class is also configured:
1.  messageSource @Bean :
@Bean(name = Array("messageSource"))
def getMessageSource: MessageSource = {
  val msgSrc:ReloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource()
  msgSrc.setBasename("classpath:/messages/message")
  msgSrc
}
Such bean give us access to the messages place in the "resource" project folder.
2.  default displayed locale by the "localeResolver" bean:
@Bean(name = Array("localeResolver"))
def getLocaleResolver: LocaleResolver = {
  val cookieLocaleResolver: CookieLocaleResolver = new CookieLocaleResolver()
  cookieLocaleResolver.setDefaultLocale(new Locale("en"))
  cookieLocaleResolver
}
3. access to the static project resources as is mentioned in to one of previous posts 

Let's start on the front-end dev. with the default tiles.xml file in the ../pages directory

  
 
 
  
  
 
 
  
  
    
    
  

  The example project has two page to display based on "standardLayout" which consists from header and footer
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>


  
     <fmt:message>
 <tiles:insertAttribute name="title" />
     </fmt:message>
     <link rel="stylesheet" href="<c:url value="/app/css/style.css" />" >
  


Take a look into github example project
After having also *.jsp pages defined we can run our Tomcat7 container
container:start
and open the web browser and call the applicaiton: 
1. http://localhost:9090/?lang=de
2. http://localhost:9090/test/web?lang=de
3. http://localhost:9090/test/web?lang=en
4. http://localhost:9090/test/web

Enjoy Tiles 3 and take a look on my github example project to get more information around

No comments: