Machine Learning Authors: Zakia Bouachraoui, Liz McMillan, Roger Strukhoff, Pat Romanski, Carmen Gonzalez

Related Topics: Java IoT, Machine Learning

Java IoT: Tutorial

Developing MVC Applications Using ZK and Spring

MVC app with ZK and Spring

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.

import com.example.userprofile.controller.UserProfileController;
UserProfileController controller = userProfileController;

Note that ‘userProfileController’ is the name of the Spring bean per its declaration
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.

More Stories By Srinivas Jaini

Srinivas Jaini is a software technologist with extensive experience in developing enterprise software applications.

CloudEXPO Stories
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected path for IoT innovators to scale globally, and the smartest path to cross-device synergy in an instrumented, connected world.
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
ScaleMP is presenting at CloudEXPO 2019, held June 24-26 in Santa Clara, and we’d love to see you there. At the conference, we’ll demonstrate how ScaleMP is solving one of the most vexing challenges for cloud — memory cost and limit of scale — and how our innovative vSMP MemoryONE solution provides affordable larger server memory for the private and public cloud. Please visit us at Booth No. 519 to connect with our experts and learn more about vSMP MemoryONE and how it is already serving some of the world’s largest data centers. Click here to schedule a meeting with our experts and executives.
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understanding as the environment changes.
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the modern business digitalization solutions. Achieve up to 50% early-stage technological process development cost cutdown with science and R&D-driven investment strategy with Codete's support.