Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Spring Tutorials >>> Spring View >>> Spring Tiles Example
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : ISHTEK
Title :
Spring Reflection
Description : POC Idea example code
More...


Written By : ISHTEK
Title :
Spring singleton
Description : Spring Container Example
More...


Written By : ISHTEK
Title :
Spring Features Updates News
Description : Bringing To Page
More...


Written By : ISHTEK
Title :
Spring Service
Description : Web Service Example
More...


Written By : ISHTEK
Title :
Spring WebService
Description : Example Code Discussed
More...


Written By : Amit
Title :
Spring Web MVC
Description : Example code discussed
More...


Written By : ISHTEK
Title :
Spring Remote Stateless SessionBean
Description : Calling SessionBean Example code
More...

Tags/Keywords : Spring and Tiles, Spring and Tiles view, Spring view, Tiles, Example, Code, Tutorial, Article, code
Author : ISHTEK
Date (Year/Month/Date): 2010-07-21 Working with Tiles and Spring View :
Tried to use Spring Web and MVC API along with the Tiles 2.1.4
This has been a learning experience while working with Spring 3.0 
and Tiles 2.1.4 version.

I tried to write a simple example on using Spring MVC and 
Web module with Tiles as the view.

After working on basic part of my example for various files such 
as my ExampleController extending Spring's Controller interface,
a *-servlet.xml file for the configuration settings related to 
Spring Web, web application descriptor file (web.xml), Tiles related
setting in Tiles.xml(default file), so many related JAR files from
Spring's, Tiles's and Log4j's API distribution zipped files.

So we will be using Tiles for the user interface screens and Spring
for controller and Model beans for data.

Spring's Dispatcher Servlet is configured in web application
descriptor file, and the url mapping is mapped to *.go.

web.xml
....
....
  <servlet>
    <servlet-name>example-web-controller</servlet-name>
	<servlet-class>
	  org.springframework.web.servlet.DispatcherServlet
	</servlet-class>
	<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>example-web-controller</servlet-name>
	<url-pattern>*.go</url-pattern>
  </servlet-mapping>
....
....
Here in this example the servlet name I choose it to be "example-web-controller", so I would have to provide another XML file with a name as "example-web-controller-servlet.xml" for Spring API to read it for looking up this example's controller class file, along with other bean definitions such as "TilesConfigurer" and "TilesViewResolver". example-web-controller-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"    
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

  <bean name="/sample.go" class="example.controller.ExampleController">
  </bean>

  <bean id="exampleTilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  </bean>

  <bean id="tilesViewResolver"
     class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
    <property name="viewClass" 
        value="org.springframework.web.servlet.view.tiles2.TilesView"/>
  </bean>
</beans>
I have used a very simple and bare minimum required tiles definitions for this example only, such as follows: tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
  "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
  "http://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
    <definition name="goodsample" template="/good.jsp">
        <put-attribute name="message" value="Good JSP"/>
    </definition>
</tiles-definitions>
So what we have got here, a definition with name as "goodsample" and the corresponding JSP file for the template as "good.jsp", with a single attribute as message. In this example the JSP file "good.jsp" is having Tiles tag library being used as shown below:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="t1" %>
<font color="green"><b><t1:getAsString name="message"/></b></font>
URL I used for testing this example is as follows: http://....../<web application name>/sample.go While running this example, initially I encountered many "no class not found exceptions", and this exceptions made me to look for many different JAR files to look for. For you reference, I am going to list those here in this page (one may or may not require all of these, but in case these are required):
  • aopalliance-alpha1.jar
  • commons-beanutils-1.8.0.jar
  • commons-digester-2.0.jar
  • commons-logging-1.1.1.jar
  • jcl-over-slf4j-1.5.8.jar
  • jstl-api-1.2.jar
  • jstl-impl-1.2.jar
  • log4j-1.2.15.jar
  • org.springframework.aop-3.0.0.RELEASE.jar
  • org.springframework.asm-3.0.0.RELEASE.jar
  • org.springframework.aspects-3.0.0.RELEASE.jar
  • org.springframework.beans-3.0.0.RELEASE.jar
  • org.springframework.context-3.0.0.RELEASE.jar
  • org.springframework.context.support-3.0.0.RELEASE.jar
  • org.springframework.core-3.0.0.RELEASE.jar
  • org.springframework.expression-3.0.0.RELEASE.jar
  • org.springframework.web-3.0.0.RELEASE.jar
  • org.springframework.web.servlet-3.0.0.RELEASE.jar
  • slf4j-api-1.5.8.jar
  • slf4j-jdk14-1.5.8.jar
  • tiles-api-2.1.4.jar
  • tiles-compat-2.1.4.jar
  • tiles-core-2.1.4.jar
  • tiles-jsp-2.1.4.jar
  • tiles-servlet-2.1.4.jar
  • (Not list all those license files required to for using these JAR files) All those who are trying to use Tiles of version 2.2.x along with Spring version 3.0.x, there is a small finding I would like to share. Initially I was using Tiles 2.2.1 with Spring Framework 3.0.0 release for this example, but I was constantly getting NullPointerException with the partial stacktrace as follows:
    java.lang.NullPointerException
    	org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory
    	   .getDefinition(UnresolvingLocaleDefinitionsFactory.java:102)
    
    After searching for clues for sometime, I tried with Tiles 2.1.4 and this example worked.
    
    
    	
    Please write your Comment on this Matter
    (This will be visible if found suitable):
    Name: *
    Email (will not be displayed): *
    Matter: *
    3,26
    Enter bigger number from above :*
    Home >>> Spring Tutorials >>> Spring View >>> Spring Tiles Example
    Visitor/User referred related external URL:
    (Visible upon review and approved by this site Administrator)
    
    Referred By Name *:
    Resource URL *: (e.g, URL should be starting with http://www.-----.---)
     
    Resource Short Description *:
    35,11
    Enter bigger number from above : *

    Please log in to add or reply to any matter<- requires login
    Log in or Register
    Copyright © 2008-2010, Interview-Questions-Tips-Forum, All Rights Reserved.
    CONTACT    PRIVACY POLICY    DISCLAIMER
     
    
    Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    Other names may be trademarks of their respective owners
    
    This web site's Terms of Use and Disclaimer :
    
    This web site provides some of the information about various technologies, example code, tips, tutorials etc. Like any printed materials,
    content of these pages may become out of date over a period of time. Therefore all visitor/users of this web site are requested/advised
    to refer to the originating parties/sources for the latest changes and happenings for detailed information. This information is not
    intended to be a substitute for the original reference provided by the originating parties/sources. These examples with source code or
    without source code, have not been thoroughly tested under all conditions. Interview-questions-tips-forum.net therefore, cannot guarantee
    or imply reliability of these example source code or programs.
    
    By accessing and using this website in any ways, including, without limitation, browsing the website pages, using any information, using
    any content and/or downloading any materials, you agree to and are bound by the terms of use described in this page and Usage Terms and Conditions.
    If you do not agree to all of the terms and conditions contained in the terms of use described in this page and
    Usage Terms and Conditions, do not use this website in any manner. If you are using the website on behalf of your
    employer, you represent that you are authorized to accept these Terms of Use on your employer's behalf.
    
    All Trademarks are property of their respective owner. Appropriate measure is being taken for providing accurate and up-to-date
    information but like any printed materials, these blog(s)/contents may eventually be outdated one day, so if you are using any of these
    information, please refer original content/documentation from respective sources. And under no circumstances shall the Author of these
    contents and/or this web site be liable for any loss, damage, expense incurred or suffered which is claimed to have occurred because of
    usage of the contents of this web site. If you have any questions/queries/feedback/suggestions then please write to this web site owner
    at contact.