-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi everybody,
I want to know how can we use the class DAO generated by ZetaDB Form Builder for other purpose?
For example in my class, i want to use a object DAO to to the access into database, but this object is always null, how can I initialize it ???
public class Test { @Resource ItemDAO itemDAO; public boolean checkExistance(int idItem) { try { Item item = itemDAO.find(idItem); (Here java.lang.NullPointerException is raised) System.out.print(item.getName()); } catch (EntityNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Thanks in advance
Could you check/post your spring-config?
<!-- ZK Spring config -->
<zksp-annot:component-scan base-package="org.zkoss.spring.jpa,org.zkforge.todo" />
<zksp:zk-config />
The DAO's extends the BasicDAO inside the org.zkoss.spring.jpa-package. You have to configure spring to scan the zk-package. W/o zk-package no EntityManager will be injected.
/Robert
thanks Robert, here my test
- I create a ZK project, use ZETA Form Builder to build a CRUD application
- CheckDAO.java , i just want to use a DAO class generated by ZETA to search a bean from database and show one of those attribut via showTheName method.
package testDAO; import javax.annotation.Resource; import org.zkoss.spring.jpa.EntityNotFoundException; import test.help_topic.Help_topicDAO; import test.help_topic.base.Help_topic; public class CheckDAO { @Resource Help_topicDAO helpDAO; public String showTheName() { try { Help_topic helpBean = helpDAO.find(1); // find bean with ID=1 return helpBean.getName(); } catch (EntityNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return "Bean not found"; } } }
- application-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:sec="http://www.springframework.org/schema/security" xmlns:zksp="http://www.zkoss.org/2008/zkspring" xmlns:zksp-annot="http://www.zkoss.org/2008/zkspring-annot" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd http://www.zkoss.org/2008/zkspring http://www.zkoss.org/2008/zkspring/zkspring.xsd http://www.zkoss.org/2008/zkspring-annot http://www.zkoss.org/2008/zkspring-annot/zkspring-annot.xsd "> <!-- ZK Spring config --> <zksp-annot:component-scan base-package="org.zkoss.spring.jpa,test,testDAO"/> <zksp:zk-config/> <!-- Injected properties --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:/config/datasource.properties</value> </list> </property> </bean> </beans>
Robert, if you did that work, let me know or show me some code, I appreciate that
Thanks
Asked: 2009-06-05 08:40:37 +0800
Seen: 1,869 times
Last updated: Nov 19 '09
ZK studio and eclipse outline problem
ZK Package configuration problem
Eclipse Autocomplete not working in ZUL files...
Syntax Error mark ... help me!
Manual Installation of ZK Studio
Can't see button text whilst running simple demo
Adding Vbox to Center layout in Java