| By Srinivas Jaini | Article Rating: |
|
| July 1, 2010 03:33 PM EDT | Reads: |
9,077 |
The ZK framework provides a variety of paradigms to develop Web applications. One the one hand it is always nice to have options, but on the other this can cause un-intentional paradigm disparities when several developers are using the framework to develop an application without a consistent design.
By and far, Model View Controller pattern has been adapted by various Web applications and frameworks (like Apache Struts, Apache Beehive PageFlows) to develop quality Web applications.
The following is an illustration of how an MVC based Web application can be developed using ZK and Spring. ZK has introduced a lot of features that enable easy integration with Spring. The source code of example application is available for download here.
The Model:
The model is usually an object or a group of objects representing a business entity. In this example, an object called UserProfile is designed to represent a user. It is defined declaratively per EJB 3 standards.
The View:
The zul page, userProfile.zul is a the page that acts as a view that provides information to the user.
The Controller:
ZK provides a convenience feature use Spring beans with minimal code. All spring beans can be accessed by their names as long as a zul page has the following declaration:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
With this declaration, any Spring bean can be accessed by its name. For example, the following zscript scriptlet accesses a Spring bean UserProfileController using its name.
<zscript>
import com.example.userprofile.controller.UserProfileController;
UserProfileController controller = userProfileController;
</zscript>
Note that ‘userProfileController’ is the name of the Spring bean per its declaration
@Controller("userProfileController")
@Scope("prototype")
public class UserProfileController {
…
}
The annotation ‘Scope’ defines scope and lifecycle of a Spring bean. By default all Spring beans are Singletons. When declared as of type ‘prototype’, Spring generates the bean objects using a factory pattern. So each call made in zscript on page render gets a new object instance, thus making sure that every user gets a new object whose life span is that of the zul page itself. Using Spring MVC framework, further options are available to specify session scoped controllers.
Published July 1, 2010 Reads 9,077
Copyright © 2010 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Srinivas Jaini
Srinivas Jaini is a software technologist with extensive experience in developing enterprise software applications.
- Book Excerpt: Introducing HTML5
- It's the Java vs. C++ Shootout Revisited!
- Patterns for Building High Performance Applications
- OpenXava 4.3: Rapid Java Web Development
- Asynchronous Logging Using Spring
- Java for Programmers (2nd Edition)
- Cross-Platform Mobile Website Development – a Tool Comparison
- Write Once Run Anywhere or Cross Platform Mobile Development Tools
- Three Buzzwords That Every CIO Hears but One They Should Listen To
- Immersing into JavaScript Frameworks
- Workday Reportedly Prepping to Go Public
- Book Review: Sams Teach Yourself Java in 24 Hours
- Book Excerpt: Introducing HTML5
- Adobe Sends Flex to the Apache Foundation
- Five Years Waiting for JRE 7: Is It Justified? (Part 1)
- Book Excerpt: Java Application Profiling Tips and Tricks
- i-Technology in 2012: Five Industry Predictions
- It's the Java vs. C++ Shootout Revisited!
- Patterns for Building High Performance Applications
- OpenXava 4.3: Rapid Java Web Development
- The Next Web Architecture
- Asynchronous Logging Using Spring
- Java for Programmers (2nd Edition)
- Is Write Once Run Anywhere Ever Going to Be a Reality?
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- JavaServer Faces (JSF) vs Struts
- The i-Technology Right Stuff
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- What's New in Eclipse?
- i-Technology Predictions for 2007: Where's It All Headed?






















