Tech I Enjoy Logo

Custom Search




  Home >> Spring Framework

I have 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 Framework v3.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 that is 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
  • (Please take care and read all those license files required for using these JAR files, as appropriate) 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. I think this example needs to be checked for making it compatible with Tiles 2.2.1 with Spring Framework version 3.0.0. If anybody interested and would like to take this up as an exercise to solve this issue that I encountered and writen as above, you are most welcome. If you have found the solution to the above exception, and if you like to share it with all of us, then please drop your findings to my email at usingframeworks @ gmail . com If found appropriate/suitable, we may show your comments in this page, with your name and date (we never disclose email id of our reader's feedback, as per this web site's privacy policy). If anything missed out , please let me know at techienjoy at yahoo . com
    Example using Spring DAO with Hibernate :
    Example using Spring DAO with Hibernate Framework Part 2.
    Spring Framework MVC and Tiles :
    Spring Framework MVC and Tiles with Example 
    source code explained.
    Spring Framework Remote Session Bean :
    Spring Framework Example source code of
    Remote Session Bean.
    Example using Spring with Hibernate :
    Example using Spring with Hibernate Framework and use
    Current Session Context.
    Spring Batch Framework Example :
    Spring Batch Framework Example source code
     and Step by step code walkthrough
    Spring Framework Web Example and WSDL :
    Spring Framework Web Example source code
    with WSDL.Step by step code walkthrough
    Example using Spring with Hibernate :
    Example using Spring with Hibernate Framework Part 1.
    Spring Framework Web Example :
    Spring Framework Web Example source code Explained.
    Spring Framework Local Stateless Session bean :
    Spring Framework Local Stateless Session bean with
    example source code explained.
    Spring Framework Singleton Example :
    Spring Framework Singleton Example source code 
    compared with GOF Singleton.
    Example using Spring DAO with Hibernate :
    Example using Spring DAO with Hibernate Framework.
    Interview Questions with answer on Spring Framework :
    Interview Questions with answer on Spring Framework.
    Spring Framework Web Example :
    Spring Framework Web Example source code Explained.
    Example using Spring with Hibernate :
    Example using Spring with Hibernate Framework Part 2.
    Spring Framework Example :
    Spring Framework Example source code Explained.
    Step by step code walkthrough


    References :
    Tags: spring dao hibernate example
    Tags: spring hibernate dao example
    Tags: spring hibernate example 2
    Tags: spring hibernate example current session context
    Tags: spring hibernate example
    Tags: Spring Interview Questions Answer
    Tags: Spring Local SLBean
    Tags: Spring MVC Tiles2
    Tags: Spring Remote SLBean
    Tags: Spring Singleton GOF Singleton Difference
    Tags: spring web example
    Tags: spring ws example
    Tags: Spring
    Tags: springws example wsdl
    

    
    
    DISCLAIMER :
    The content provided in this page is not warranted and/or guaranteed by techienjoy.com. 
    techienjoy.com is not liable for any negative consequences that may result/arise from 
    implementing directly/indirectly any information covered in these pages/articles/tutorials.
    
    All contents of this site is/are written and provided on an "AS IS" basis,
    without WARRANTIES or conditions of any kind, either express or implied, including, without
    limitation, merchantability, or fitness for a particular purpose. You are solely responsible
    for determining the appropriateness of using or refering this and assume any risks associated
    with this.
    
    In spite of all precautions taken to avoid any typo in these pages, there might be some 
    issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
    extends sincerest apologies to all our visitors for the same.
    
    
    

    Android Examples || Android Examples

    © Copyright 2010-2012, TECHIENJOY, All Rights Reserved.      Privacy Policy     Disclaimer & Terms & Conditions