-
Aug 28th, 2009, 11:47 AM
#1
Spring & JSF Integration: dao is null after jsf navigation
Hello all,
I am trying to convert a JSF/iBatis dao application to JSF/Spring Dao. I have configured the spring dao and service layer objects and was able to run the application. At least the first pages are displayed correctly with dao being able to fetch data from the database. However, when I navigate to the next page, the dao objects used in the service layer become null. What am i doing wrong. I have congured spring like follows:
spring.xml (all of spring related DI configurations went here)
<!-- JNDI datasource -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName">
<value>java:ds/CirDS</value>
</property>
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
<property name="configLocation">
<value>classpath:gov/bf/cir/services/dao/sql/sql-map-config.xml</value>
</property>
<property name="useTransactionAwareDataSource">
<value>true</value>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClient Template">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
<!-- Dao -->
<bean id="confDaoImp" class="gov.bf.cir.services.dao.impl.ConfDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
<bean id="deviseDaoImp" class="gov.bf.cir.services.dao.impl.DeviseDaoImpl" >
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
<bean id="docDaoImp" class="gov.bf.cir.services.dao.impl.DocDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
....
<!-- Services -->
<bean id="demDocService" class="gov.bf.cir.services.op.DemDocService">
<property name="docDao" ref="docDaoImp"/>
....
</bean>
JSF Backing bean implementation: the service layer object is instantiated in the backing bean constructor.
public class DemDocForm implements Serializable
{
private demService DemDocService;
...
public DemDocForm()
{
demService = SpringInit.getApplicationContext().getBean("demDoc Service"));
}
}
Service implementation: the dao object should be injected into the service object every time it is instantiated. But it seem the dao are injected
only when the service object is first created when the backing bean is created. Don't know what happens after, if and when the
backing bean is serialized and then deserialized. The backing bean has scope "session" and face-config.xml does not contain anything specific to spring (old faces configuration for iBatis Dao).
public class DemDocService
{
private docDao DocDao;
...
public DemDocService()
{}
public getDocDao(){
return this.docDao;
}
public setDocDao( DocDao docDao)
{
this.docDao = docDao;
}
}
Thanks in advance for any help.
-
Aug 31st, 2009, 07:15 AM
#2
Any thoughs. I believe Spring DI did not work inject correctly the DAO during the backing bean serialization and deserialization.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules