Skip to content

Instantly share code, notes, and snippets.

@senthilmuthiah
Created January 29, 2013 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senthilmuthiah/4662539 to your computer and use it in GitHub Desktop.
Save senthilmuthiah/4662539 to your computer and use it in GitHub Desktop.
<?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>
<context:component-scan base-package="zkCommon.zkSpringJPA">
</context:component-scan>
<tx:annotation-driven />
<context:annotation-config />
</beans>
package zkCommon.zkSpringJPA;
import java.util.List;
import org.springframework.stereotype.Component;
public interface ZkSpringJpaExampleDao {
public List<ZkSpringJpaExample> findAll();
}
package zkCommon.zkSpringJPA;
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;
}
}
<zk>
<window id="zkspringjpaexampleListing" title="Users List"
height="90%" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('zkCommon.zkSpringJPA.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>
package zkCommon.zkSpringJPA;
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.zkplus.spring.SpringUtil;
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);
}
}
package zkCommon.zkSpringJPA;
import java.util.List;
import org.springframework.stereotype.Service;
@Service
public interface ZkSpringJpaExampleService {
public List<ZkSpringJpaExample> findAll();
}
package zkCommon.zkSpringJPA;
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;
@Transactional(readOnly=true)
public List<ZkSpringJpaExample> findAll() {
Messagebox.show("asdasdsa");
return ZkSpringJpaExampleDao.findAll();
}
public ZkSpringJpaExampleDao getZkSpringJpaExampleDao() {
return ZkSpringJpaExampleDao;
}
public void setZkSpringJpaExampleDao(ZkSpringJpaExampleDao zkSpringJpaExampleDao) {
ZkSpringJpaExampleDao = zkSpringJpaExampleDao;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment