Using the DAO object of ZetaDB Form Builder ?
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
Still need help ...
Thanks
You declared a Test class here means it also need to be managed by Spring.
Why not just use Spring BeanFactory to get ItemDAO instance back at very first?
I have done this but when I do it I can get the bean but the basic dao service inside it is null.
- by Jacques
Hi ,
I am having the same probleme. Did you find a solution??
Thanks
ZK - Open Source Ajax Java Framework
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