Vaadin with Service & DAO Layer

  1. this is my applicationServlet
<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 	http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop 		http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/context 	http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jee 		http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang 		http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/tx 		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util 		http://www.springframework.org/schema/util/spring-util.xsd
		http://www.springframework.org/schema/mvc 		http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<!-- Json Viewer -->
	<mvc:annotation-driven />

	<context:annotation-config />
	<context:component-scan base-package="com.priyan.contact" />

	<!-- Configure the Message properties -->
	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basename" value="classpath:messages" />
		<property name="defaultEncoding" value="UTF-8" />
	</bean>
	<!-- Configure the JDBC properties -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
		p:location="/WEB-INF/jdbc.properties" />

	<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
		<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" />
	</bean>

	<bean id="nativeJdbcExtractor"
		class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" />

	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.databaseurl}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	<bean id="contactDAO" class="com.priyan.contact.dao.ContactDAOImpl">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- Initialize Session -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation">
			<value>classpath:hibernate.cfg.xml</value>
		</property>
		<property name="configurationClass">
			<value>org.hibernate.cfg.AnnotationConfiguration</value>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${jdbc.dialect}</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
	</bean>

	<!-- Add Transaction Handling -->
	<tx:annotation-driven />

	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- Add Ajax Capability -->
	<bean id="jacksonMessageConverter"
		class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />

	<bean id="ajaxViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
		<property name="viewClass"
			value="org.springframework.webflow.mvc.view.FlowAjaxTilesView" />
	</bean>
</beans>
  1. this is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>myproject</display-name>
	<context-param>
		<description>Vaadin production mode</description>
		<param-name>productionMode</param-name>
		<param-value>false</param-value>
	</context-param>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.context.request.RequestContextListener
		</listener-class>
	</listener>
	<servlet>
		<servlet-name>Myproject Application</servlet-name>
		<servlet-class>
			com.vaadin.terminal.gwt.server.ApplicationServlet
		</servlet-class>
		<init-param>
			<description>Vaadin application class to start</description>
			<param-name>application</param-name>
			<param-value>
				com.priyan.contact.vaadin.Test
			</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>Myproject Application</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
</web
  1. this is my DAOImpl

package com.priyan.contact.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.priyan.contact.form.INPercentageBean;

@Repository
public class ContactDAOImpl implements ContactDAO {

	private JdbcTemplate jdbcTemplate;

	@Autowired
	private SessionFactory sessionFactory;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public List<INPercentageBean> getINPercentage() {
		@SuppressWarnings("unchecked")
		List<INPercentageBean> inPercentageBeanList = jdbcTemplate
				.query("select round((count(WITHIN_SLA)/count(*))*100,2) SLA_PER "
						+ "from ("
						+ "select ASSIGNED_DIVISION, LOB,CASE WHEN (DATE_COMMITED-CASE WHEN DATE_CLOSED  is null THEN SYSDATE ELSE DATE_CLOSED END)<0 THEN SR_NUMBER END SLA_BREACHED,"
						+ " CASE WHEN (DATE_COMMITED-CASE WHEN DATE_CLOSED  is null THEN SYSDATE ELSE DATE_CLOSED END)>=0 THEN SR_NUMBER END  WITHIN_SLA "
						+ "from sbl_service_request_v "
						+ "where SR_TYPE ='Complaint' "
						+ "and ASSIGNED_DIVISION  in ('RNP_OPS','VAS_OPS','IN_OPS','PS_OPS','CS_OPS','IDD_OPS','ES_VO_VI')"
						+ "and to_char(DATE_COMMITED,'MM-YY') =to_char(sysdate,'MM-YY'))",
						new Object[] {}, new RowMapper() {
							public INPercentageBean mapRow(ResultSet rs,
									int rowNum) throws SQLException {
								INPercentageBean inPercentageBean = new INPercentageBean();
								inPercentageBean.setSlaPer(rs
										.getDouble("SLA_PER"));
								return inPercentageBean;
							}
						});
		return inPercentageBeanList;
	}

}

  1. this is my ServiceImpl

package com.priyan.contact.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.priyan.contact.dao.ContactDAO;
import com.priyan.contact.form.INPercentageBean;

@Service
public class ContactServiceImpl implements ContactService {

	@Autowired
	private ContactDAO contactDAO;

	@Transactional
	public List<INPercentageBean> getINPercentage() {
		return contactDAO.getINPercentage();
	}

}

  1. this is my Vaadin UI Class

package com.priyan.contact.vaadin;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.priyan.contact.dao.ContactDAO;
import com.priyan.contact.form.INPercentageBean;
import com.priyan.contact.service.ContactService;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;

@Configurable
public class Test extends com.vaadin.Application {
	
	@Autowired
	private ContactService contactService;
	
	protected transient ApplicationContext springContext;
	
	public void init() {
		
		final Window main = new Window("Hello Window");
		final Window myWindow = new Window("This is new window");
		setMainWindow(main);
		main.addComponent(new Label("Hello Label"));

		final Button button = new Button("Push it");
		button.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				button.setCaption("You pushed it");
				main.removeWindow(myWindow);
			}
		});
		main.addComponent(button);

		main.addComponent(new Button("What is the Time now ? ",
				new Button.ClickListener() {
					public void buttonClick(ClickEvent event) {
						main.showNotification("The time is : " + new Date());
						main.addWindow(myWindow);
					}
				}));

		setMainWindow(main);
		
//		List<INPercentageBean> myBean =
				contactService.getINPercentage();
		/*Iterator itr = myBean.iterator(); 
		while(itr.hasNext()) {
		    Object element = itr.next(); 
		    System.out.print(element + " ");
		} */
	}
}

ERROR IS NO RESULT & OCCUR

Please help me to solve this issue.

is wrong ? any other modification have to define ???

Hi,

The problem is that the Application has not been “weaved” - that is, the application class needs to be processed immediately after it is instantiated to add in the autowire objects.
Now, assuming that you haven’t done compile-time weaving, you probably want to enable load-time weaving.

This is a Spring issue, by the way, and nothing to do with Vaadin.

Here’s the
Spring documentation
on load-time weaving AOP, which is essentially what “drives” the autowiring. Essentially, you’ll want to add context:load-time-weaver/ to your application-context.xml, and if you’re running tomcat, stick the org.springframework.instrument.tomcat.jar in the lib directory, and tweak a (tomcat) context.xml file

It is also possible to do autowiring with Vaadin without doing Spring AOP - by creating and using a different ApplicationServlet , but it is not something I’ve done - others may be able to help.

Cheers,

Charles.

I deleted the other copies of this post. Please only post in one thread.

just below code put in application servlet is enough ?

<context:load-time-weaver/>

sorry i’m first to this forum…thanks for the advice

Um, no.

As I said reasonably clearly above, you need to change the spring config file AND add a jar into tomcat lib AND tweak a tomcat config file.

Please read the Spring Documentation reference; it explains what to do. It may be a little long, but that’s because it’s explaining complicated things. It’s clear and readable.

Cheers,

Charles.

thanks bro’

i’ll try to read it