Archive for the ‘Spring Framework’ Category
Spring Hibernate DAO Implementation with interface
Intro
Assuming we have a module called Account Management in our project called foo,
We might can make use of the following package structure.
- foo.service.AccountManagement
- foo.service.AccountManagementImpl
- foo.dao.AccountDAO
- foo.dao.hibernate.AccountDAOImpl (In this case hibernate)
- foo.model.Account
Spring Wiring
<bean id="accountDAO" class="rb.dao.hibernate.AccountDAOImpl"></bean>
<bean id="accountManagement" class="foo.service.AccountManagementImpl">
<property name="accountDAO">
<ref bean="accountDAO"/>
</property>
</bean>
So note that you can replace the accountDAO with some other implementation class, probably using pure JDBC or ibatis.
Summary
As the experts say, always code to interfaces to cater for different implementations.
Javascript support in Spring Velocity Macros
I’m using Velocity templates as the “view” for a new Spring MVC project.
Velocity Spring macros are available which can be used to bind object attributes to the html form elements.
While reading Chapter 14 from Spring MVC documentation, i noticed the VTL definition for a html select element looks like #springFormSingleSelect( $path $options $attributes).
We can pass javascript behaviour into the $attribute parameter like,
#springFormSingleSelect( "new_match.competition" $competitions "onchange=updateTeams()")
which produces,
<select id="competition" name="competition" onchange=updateTeams()> <option value="1">English Premier League</option> <option value="2">Spanish Primera Liga</option> <option value="3">Italian Serie A</option> </select>
