
Originally Posted by
TSH
Maybe I don't understand your question, but I use Dependency Injection as usual to my objects and then expose them to DWR, like.
Code:
<bean id="myController" class="my.namespace.MyController">
<property name="myProp" ref="myProp"/>
<dwr:remote javascript="MyController" />
</bean>
I tried that. I added the dwr:remote line to the myapp-servlet.xml like this:
Code:
<bean id="productManager" class="springapp.service.SimpleProductManager">
<property name="productDao" ref="productDao"/>
<dwr:remote javascript="ProductManager" />
</bean>
ProductManager, in turn, calls the productDao class that pull data from the database. The DAO still remained null and uninitialized when productManager is invoked by DWR from JSP - so the problem persists.
In myapp-servlet.xml I have the DAO declared as follows - do I need to add/change anything:
Code:
<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/spring"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
</bean>
<bean id="productDao" class="springapp.repository.JdbcProductDao">
<property name="dataSource" ref="dataSource" />
</bean>
Here is DWR call from JSP:
Code:
<script type='text/javascript' src='/springdwr/dwr/interface/ProductManager.js'></script>
<script type='text/javascript' src='/springdwr/dwr/engine.js'></script>
<script type='text/javascript' src='/springdwr/dwr/util.js'></script>
<script>
function handleGetData(str) {
alert(str);
}
ProductManager.getProductDesc(handleGetData);
</script>