Integrate ZK with Spring MVC 3"

From Documentation
Line 46: Line 46:
 
<context:component-scan base-package="demo.data.service" />
 
<context:component-scan base-package="demo.data.service" />
 
 
<bean id="jsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 
<property name="prefix" value="/WEB-INF/" />
 
<property name="prefix" value="/WEB-INF/" />
 
<property name="suffix" value="" />
 
<property name="suffix" value="" />

Revision as of 03:17, 7 November 2012

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

DocumentationSmall Talks2012NovemberIntegrate ZK with Spring MVC 3
Integrate ZK with Spring MVC 3

Author
Vincent Jian, Engineer, Potix Corporation
Date
November 06, 2012
Version
ZK 6.0.2/6.5.0 , Spring MVC 3.1.2

Introduction

Spring MVC is a request-based Model-View-Controller web framework. It is easy to define page flow with Spring MVC. However, when the website is getting complex, it is hard to maintain the page flows. Thus, it is not a bad idea to implement some part of functions by component-based (ajax-based) framework like ZK framework to reduce the page flows. This article will demonstrate how to communite between Spring MVC to ZK MVVM with a simple shopping cart sample.

Setup the sample project

In this article, we use Eclipse with m2eclipse plugin to create a new ZK Maven project, check the installation guide here.

  • First, we need to add Spring MVC dependency in the pom.xml file.
<!-- Spring MVC dependency -->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-webmvc</artifactId>
	<version>3.1.2.RELEASE</version>
</dependency>
<!-- ZK dependency -->
<!-- ommitted -->
  • Then, define SpringMVC DispatherServlet in web.xml file.
<!-- Spring MVC servlet -->
<servlet>
	<servlet-name>springmvc</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>springmvc</servlet-name>
	<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- ZK servlet -->
<!-- ommitted -->
  • Finally, create a [servlet-name]-servlet.xml file under WEB-INF folder. Note that the file name pattern must match the servlet name defined in web.xml, in this sample the file name is springmvc-servlet.xml. In this file we can define the ViewResolver.
<beans ...>
	<mvc:annotation-driven />
	<mvc:resources location="/images/" mapping="/img/**" />
	
	<context:component-scan base-package="demo.controller.springmvc" />
	<context:component-scan base-package="demo.data.service" />
	
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/" />
		<property name="suffix" value="" />
	</bean>
</beans>

Communiation between Spring MVC and ZK MVVM

Spring MVC Controller to ZK MVVM

ZK MVVM to Spring MVC Controller

Consolution

Download

Comments



Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.