Requirement Constraints

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 28 January 2013

ZK With Spring + JPA + Hibernate Entity Manager

Posted on 18:10 by Unknown

In this article, let us see how we can integrate ZK With spring, JPA and Hibernate Entity Manager.

Technologies Used

    1. ZK 6.5 CE Version
    2. Hibernate Entity Manager Version 4.1.9 Final.
    3. Hibernate Core Version 4.1.9 Final
    4. Spring ORM Version 3.2.0
    5. MySQL version 5

Reference

  • ZK Integration with Hibernate
  • Spring by Example
  • http://www.aoiblog.com/step-by-step-configuration-of-spring-hibernate-and-jpa/
  • http://hop2croft.wordpress.com/2011/07/06/jpa-basic-example-with-entitymanager-spring-and-maven/
  • Not a good idea to have Spring managing the composer
  • Warning: Register a Composer (or ViewModel) as a Spring bean

Project Name and Structure

ZKSpringJPA

image

Step 1:

If you are new ZK, then you can setup the Development environment by downloading this document.

Step 2:

MySQL Setup. Let us create the following table in MySQL. Let us create the following table and insert two records by default.
CREATE TABLE `zkspringjpaexample` 
(
`ID` bigint(20) NOT NULL auto_increment,
`FirstName` varchar(100) default NULL,
`LastName` varchar(100) default NULL,
`LoginName` varchar(100) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


Step 3:

Now let us create ZK Maven Project. By default POM File will point ZK 6.0.1 Version. we will change this to latest version 6.5.0 and also we will include all the dependency. You can copy the below POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ZKSpringJPA</groupId>
<artifactId>ZKSpringJPA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<zk.version>6.5.0</zk.version>
<commons-io>1.3.1</commons-io>
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
<packname>-${project.version}-FL-${maven.build.timestamp}</packname>
<jsr330.version>1</jsr330.version>
<spring-data-jpa.version>1.0.3.RELEASE</spring-data-jpa.version>
<servlet-api.version>2.4</servlet-api.version>
<slf4j.version>1.6.1</slf4j.version>
</properties>
<packaging>war</packaging>
<name>The ZKExamples Project</name>
<description>The ZKExamples Project</description>
<licenses>
<license>
<name>GNU LESSER GENERAL PUBLIC LICENSE, Version 3</name>
<url>http://www.gnu.org/licenses/lgpl.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<repositories>
<repository>
<id>ZK CE</id>
<name>ZK CE Repository</name>
<url>http://mavensync.zkoss.org/maven2</url>
</repository>
<repository>
<id>ZK EVAL</id>
<name>ZK Evaluation Repository</name>
<url>http://mavensync.zkoss.org/eval</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>zkmaven</id>
<name>ZK Maven Plugin Repository</name>
<url>http://mavensync.zkoss.org/maven2/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkbind</artifactId>
<version>${zk.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zul</artifactId>
<version>${zk.version}</version>
</dependency>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkplus</artifactId>
<version>${zk.version}</version>
</dependency>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zhtml</artifactId>
<version>${zk.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io}</version>
</dependency>

<!-- ZK 5 breeze theme <dependency> <groupId>org.zkoss.theme</groupId>
<artifactId>breeze</artifactId> <version>${zk.version}</version> <optional>true</optional>
</dependency> -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.9.Final</version>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.22</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Run with Jetty -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Compile java -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Build war -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.1.1</version>
</plugin>
<!-- Pack zips -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>webapp</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>ZKSpringJPA${packname}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly/webapp.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>


Step 4:

Now let us create our domain object as follows
package zkMVVM.zKMVVMSpringJPA;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "zkspringjpaexample")
public class ZkSpringJpaExample {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@Column(name = "firstName")
private String firstName;

@Column(name = "LastName")
private String lastName;

@Column(name = "loginName")
private String loginName;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getLoginName() {
return loginName;
}

public void setLoginName(String loginName) {
this.loginName = loginName;
}


}


Step 5:

Now let us create Service and DAO Layers as follows.
ZkSpringJpaExampleService.java
package zkMVVM.zKMVVMSpringJPA;

import java.util.List;

public interface ZkSpringJpaExampleService {
public List<ZkSpringJpaExample> findAll();
}

ZkSpringJpaExampleServiceImpl.java

package zkMVVM.zKMVVMSpringJPA;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

public class ZkSpringJpaExampleServiceImpl implements ZkSpringJpaExampleService {

private ZkSpringJpaExampleDao ZkSpringJpaExampleDao;

@Transactional(readOnly=true)
public List<ZkSpringJpaExample> findAll() {
return ZkSpringJpaExampleDao.findAll();
}

public ZkSpringJpaExampleDao getZkSpringJpaExampleDao() {
return ZkSpringJpaExampleDao;
}

public void setZkSpringJpaExampleDao(ZkSpringJpaExampleDao zkSpringJpaExampleDao) {
ZkSpringJpaExampleDao = zkSpringJpaExampleDao;
}


}



ZkSpringJpaExampleDao.java
package zkMVVM.zKMVVMSpringJPA;

import java.util.List;

public interface ZkSpringJpaExampleDao {
public List<ZkSpringJpaExample> findAll();


}

ZkSpringJpaExampleDaoImpl.java
package zkMVVM.zKMVVMSpringJPA;


import java.util.LinkedList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;


@Repository
public class ZkSpringJpaExampleDaoImpl implements ZkSpringJpaExampleDao {

@PersistenceContext
private EntityManager em;


@SuppressWarnings("unchecked")
public List<ZkSpringJpaExample> findAll() {
List<ZkSpringJpaExample> exList = new LinkedList<ZkSpringJpaExample>();
Query query = em.createQuery("from ZkSpringJpaExample as ex");
exList = query.getResultList();
return exList;
}
}


Step 6:

Next step to create the ZUL File and its VM File as follows
zkspringjpaexampleListing.zul
<zk>
<window id="zkspringjpaexampleListing" title="Users List"
height="90%" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('zkMVVM.zKMVVMSpringJPA.ZKSpringJPAExampleListVM')">
<separator />
<listbox id="" mold="paging" pageSize="11" pagingPosition="top"
selectedItem="@bind(vm.selectedItem)"
model="@load(vm.examplesListData)">
<listhead sizable="true">
<listheader label="First Name" sort="auto(firstName)" />
<listheader label="Loast Name" sortDirection="ascending"
sort="auto(lastName)" />
<listheader label="Login Name" />
</listhead>
<template name="model" var="p1">
<listitem>
<listcell label="@load(p1.firstName)" />
<listcell label="@load(p1.lastName)" />
<listcell label="@load(p1.loginName)" />
</listitem>
</template>
</listbox>
</window>
</zk>


ZKSpringJPAExampleListVM.java

package zkMVVM.zKMVVMSpringJPA;

import java.util.List;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.ListModelList;

@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class ZKSpringJPAExampleListVM {

@WireVariable
private ZkSpringJpaExampleService ZkSpringJpaExampleService;
private ZkSpringJpaExample selectedItem;


public ZkSpringJpaExample getSelectedItem() {
return selectedItem;
}

public void setSelectedItem(ZkSpringJpaExample selectedItem) {
this.selectedItem = selectedItem;
}

@AfterCompose
public void initSetup(@ContextParam(ContextType.VIEW) Component view) {
Selectors.wireComponents(view, this, false);

}

public List<ZkSpringJpaExample> getexamplesListData() {
List<ZkSpringJpaExample> result = ZkSpringJpaExampleService.findAll();
return new ListModelList<ZkSpringJpaExample>(result);
}

}

Step 7:

Next step to create the persistence.xml file  as follows. Here I have created under the resource folder, so make sure that this folder is added in the build path.
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.0">

<persistence-unit name="ZKSpringJPA" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="1234" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/ZKExamples" />
</properties>
</persistence-unit>
</persistence>




Step 8:

Next step to create the applicationContext.xml in WEB-INF Folder as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
>

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/ZKExamples" />
<property name="username" value="root" />
<property name="password" value="1234" />
</bean>

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ZKSpringJPA" />
</bean>


<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>



<bean id="ZkSpringJpaExampleDao" class="zkMVVM.zKMVVMSpringJPA.ZkSpringJpaExampleDaoImpl" />
<bean id="ZkSpringJpaExampleService" class="zkMVVM.zKMVVMSpringJPA.ZkSpringJpaExampleServiceImpl">
<property name="ZkSpringJpaExampleDao" ref="ZkSpringJpaExampleDao" />
</bean>

<tx:annotation-driven />

<context:annotation-config />



</beans>


Step 9:

Finally we will refer the applicationContext.xml in the web.xml as follows

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<description><![CDATA[My ZK Application]]></description>
<display-name>ZKSpringJPA</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- Loads the Spring web application context -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring filter -->
<filter>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- //// -->

<!-- //// -->
<!-- ZK -->
<listener>
<description>ZK listener for session cleanup</description>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<description>ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>

<!-- Must. Specifies URI of the update engine (DHtmlUpdateServlet). It
must be the same as <url-pattern> for the update engine. -->
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<!-- Optional. Specifies whether to compress the output of the ZK loader.
It speeds up the transmission over slow Internet. However, if you configure
a filter to post-processing the output, you might have to disable it. Default:
true <init-param> <param-name>compress</param-name> <param-value>true</param-value>
</init-param> -->
<!-- [Optional] Specifies the default log level: OFF, ERROR, WARNING, INFO,
DEBUG and FINER. If not specified, the system default is used. <init-param>
<param-name>log-level</param-name> <param-value>OFF</param-value> </init-param> -->
<load-on-startup>1</load-on-startup><!-- Must -->
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<!-- [Optional] Uncomment it if you want to use richlets. <servlet-mapping>
<servlet-name>zkLoader</servlet-name> <url-pattern>/zk/*</url-pattern> </servlet-mapping> -->
<servlet>
<description>The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>

<!-- [Optional] Specifies whether to compress the output of the ZK loader.
It speeds up the transmission over slow Internet. However, if your server
will do the compression, you might have to disable it. Default: true <init-param>
<param-name>compress</param-name> <param-value>true</param-value> </init-param> -->
<!-- [Optional] Specifies the AU extension for particular prefix. <init-param>
<param-name>extension0</param-name> <param-value>/upload=com.my.MyUploader</param-value>
</init-param> -->
</servlet>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>

<!-- [Optional] Uncomment if you want to use the ZK filter to post process
the HTML output generated by other technology, such as JSP and velocity.
<filter> <filter-name>zkFilter</filter-name> <filter-class>org.zkoss.zk.ui.http.DHtmlLayoutFilter</filter-class>
<init-param> <param-name>extension</param-name> <param-value>html</param-value>
</init-param> <init-param> <param-name>compress</param-name> <param-value>true</param-value>
</init-param> </filter> <filter-mapping> <filter-name>zkFilter</filter-name>
<url-pattern>your URI pattern</url-pattern> </filter-mapping> -->
<!-- //// -->

<!-- ///////////// -->
<!-- DSP (optional) Uncomment it if you want to use DSP However, it is turned
on since zksandbox uses DSP to generate CSS. <servlet> <servlet-name>dspLoader</servlet-name>
<servlet-class>org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>
<init-param> <param-name>class-resource</param-name> <param-value>true</param-value>
</init-param> </servlet> <servlet-mapping> <servlet-name>dspLoader</servlet-name>
<url-pattern>*.dsp</url-pattern> </servlet-mapping> -->

<!-- /////////// -->
<!-- [Optional] Session timeout -->
<session-config>
<session-timeout>60</session-timeout>
</session-config>

<!-- [Optional] MIME mapping -->
<mime-mapping>
<extension>doc</extension>
<mime-type>application/vnd.ms-word</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>
<mime-mapping>
<extension>htm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpeg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>text/javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xml</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>zhtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>zul</extension>
<mime-type>text/html</mime-type>
</mime-mapping>

<welcome-file-list>
<welcome-file>index.zul</welcome-file>
<welcome-file>index.zhtml</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>zkspringjpaexampleListing.zul</welcome-file>
</welcome-file-list>
</web-app>


Finally, you can run and see the output as follows
image
You can download the source here


Step 10:


In the above example, we have used XML Configuration to initialize our bean. Normally you declare all the beans or components in XML bean configuration file, so that Spring container can detect and register your beans or components. Actually, Spring is able to auto scan, detect and instantiate your beans from pre-defined project package, no more tedious beans declaration in in XML file.This can be achieved by using context:component-scan element in xml configuration file

References
  • http://www.mkyong.com/spring/spring-auto-scanning-components/
  • www.techferry.com/articles/spring-annotations.html


Now let us convert the above example to Spring Annotation. Thanks to gekkio who helped me to achieved this

There is no change in zul file and its VM. And also there is no change in the interface. We need to just add @Service and @Autowired annotation in the ZkSpringJpaExampleServiceImpl.java file as shown here.


  • import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    import org.zkoss.zul.Messagebox;
    @Service
    public class ZkSpringJpaExampleServiceImpl implements ZkSpringJpaExampleService {

    @Autowired
    private ZkSpringJpaExampleDao zkSpringJpaExampleDao;


    Now we need to change our applicationContext.xml. Remove the manual declaration of the bean and include auto scan feature.
    context:component-scan base-package="zkMVVM.zKMVVMSpringJPA">
        </context:component-scan>

    In the ZKSpringJPAExampleListVM.java, we have declared as follows
    @WireVariable
        private ZkSpringJpaExampleService zkSpringJpaExampleService;

    ZK @WireVariable injects by name, not by type, so the variable name must be an exact match to the bean name. Note that Spring @Autowired by default injects by type, so the @Autowired variable name can be anything and it will work.  So additionally we need to match the name in the xml file as follows
    <bean id="zkSpringJpaExampleService" class="zkMVVM.zKMVVMSpringJPA.ZkSpringJpaExampleServiceImpl"   />

    Alternate method as follows

    You can customize names by adding them to the annotations. For example:
    @Service("zkSpringJpaExampleService")
    public class ZkSpringJpaExampleServiceImpl ...
    Now the bean gets registered as "zkSpringJpaExampleService", so that should be the variable name:
    @WireVariable
    private ZkSpringJpaExampleService zkSpringJpaExampleService;

    You can download the source here
  • Email ThisBlogThis!Share to XShare to Facebook
    Posted in ZK Spring | No comments
    Newer Post Older Post Home

    0 comments:

    Post a Comment

    Subscribe to: Post Comments (Atom)

    Popular Posts

    • ZK Example for inline Editing with Add New and Delete
      I am quite impressed on this demo from ZK . But adding new record and delete existing record is missing as part of typical CRUD. So i thoug...
    • EDI 5010 Documentation 837 Professional - Loop 2010BB Payer Name
      2010BB Payer Name          In this loop, all the information will be taken from Insurance master screen. Take a look of our sample screen...
    • EDI 5010 Documentation–837 - BHT - Beginning of Hierarchical Transaction
      BHT – Beginning of Hierarchical Transaction Loop Seg ID Segment Name Format Length Ref# Req Value   BHT Beginning of Hier...
    • Hibernate Validator Example 2
      In this example, we will see some more validation constraints such as @email, @past, @length, etc. And also we will also define custom error...
    • ZK Passing Parameter between two files using MVVM–Part 1
      Overview This is the first series of articles about Passing parameter between two zul files using MVVM Design pattern .This article will fo...
    • MVVM Command annotation and Notify change example
      Here is an example, how to pass parameter on a zul through MVVM Command binding annotation. ZK URL http://books.zkoss.org/wiki/ZK%20Develo...
    • History of Present Illness
      HPI - One of the main component of Clinical History. What is an HPI ? The history of present illness (HPI) is a chronological description...
    • Patient Demographics
      Patient browse (search) is the key element for any EMR / PMS Software. In my past 15 years experience, i involved more than 5 times in desig...
    • ViewModel Class Java Annotation @Init, @NotifyChange, @Command
      In following sections we'll list all syntaxes that can be used in implementing a ViewModel and applying ZK bind annotation. The ZK binde...
    • Good Website Design Links
      Form Design Label Placement in Forms International Address Fields in Web Forms 40 Eye-Catching Registration Pages blog-comment-form-...

    Categories

    • Billing Process
    • C Workbook
    • C++ Workbook
    • Eclipse Tips
    • EDI 5010
    • EMR Appointment Features
    • EMR Labs Stuff
    • EMR PMS Links
    • EMR Use cases
    • EMR Vital Sign
    • Good Website Design
    • Hibernate Criteria Queries
    • Hibernate Introduction
    • Hibernate Introduction Setup
    • Hibernate Mapping
    • Hibernate POC
    • Hibernate Validator
    • Hibernate–Java Environment setup
    • HPI
    • Java
    • Maven
    • MU Certification
    • NPI
    • PQRS
    • Practice Management System
    • Spring Security
    • Tech Links
    • Today Tech Stuff
    • zk
    • ZK Hibernate
    • ZK 5 Databinding
    • ZK Application
    • ZK Calling Another ZUL
    • ZK CheckBox
    • ZK CreateComponents
    • ZK CSS
    • ZK extended Components
    • ZK Foreach
    • ZK Forum Posts
    • ZK Framework
    • ZK Hibernate Setup
    • ZK ID Space
    • ZK Include
    • ZK Installation
    • ZK iReport
    • ZK Layout
    • ZK Listitem Pagination
    • ZK Message Box
    • ZK MVC
    • ZK MVC Combox Box
    • ZK MVC CRUD Examples
    • ZK MVC Listbox
    • ZK MVVM
    • ZK MVVM Combo
    • ZK MVVM CRUD
    • ZK MVVM ListBox
    • ZK Spring
    • ZK TextBox

    Blog Archive

    • ▼  2013 (105)
      • ►  December (3)
      • ►  September (7)
      • ►  August (13)
      • ►  July (1)
      • ►  June (11)
      • ►  May (3)
      • ►  April (14)
      • ►  March (19)
      • ►  February (21)
      • ▼  January (13)
        • ZK With Spring + JPA + Hibernate Entity Manager
        • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
        • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
        • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
        • ZK Datebox: Customize Datebox as Yearbox/Monthbox
        • Listing Search using MVC Pattern
        • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
        • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
        • Some Button CSS In ZK
        • ZK Passing Parameter between two files using MVC -...
        • How to set Textbox Maxlength in the view model ?
        • MVVM Pass Parameter between two zul files using UR...
        • Spring Security Form Login Example
    • ►  2012 (177)
      • ►  December (1)
      • ►  November (13)
      • ►  October (19)
      • ►  September (24)
      • ►  August (26)
      • ►  July (6)
      • ►  June (37)
      • ►  May (30)
      • ►  April (16)
      • ►  March (1)
      • ►  January (4)
    • ►  2011 (5)
      • ►  December (1)
      • ►  November (1)
      • ►  July (1)
      • ►  June (1)
      • ►  April (1)
    • ►  2010 (1)
      • ►  September (1)
    Powered by Blogger.

    About Me

    Unknown
    View my complete profile