Hello,
Can anyone please help me out on the below? I am new to GWT and I have been trying a lot to get a starter app running using GWT, Spring and hibernate.
I was able to set up basic app but now I want to use RequestFactory with Spring MVC. After searching a lot I came across few links to get started but I am not able to completely figure out how to get the configuration right, and my app is not working :( .
Can anyone please suggest me where I can get a sample app with RequestFactory and SpringMVC configured so that I can get the settings right. Or help me to get my app running.
I had followed the instructions given in http://jsinghfoss.wordpress.com/2011/08/10/gwt-2-2-0-requestfactory-spring-3-0-x-integration/ .
I am using GWT 2.4 and spring 3.
My web.xml is :
<web-app>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>SimpleRPC.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring context -->
<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>
<!-- SpringGwt remote service servlet -->
<servlet>
<servlet-name>simpleRPC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>simpleRPC</servlet-name>
<url-pattern>/gwtspring/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>authServlet</servlet-name>
<servlet-class>org.spring4gwt.examples.simplerpc.server.AuthServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>authServlet</servlet-name>
<url-pattern>/gwtspring/auth</url-pattern>
</servlet-mapping>
</web-app>
simpleRPC-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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-3.0.xsd">
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/gwtspring=gwtRequestFactoryController
</value>
</property>
</bean>
<bean id="gwtSpringServiceLayerDecorator"
class="org.spring4gwt.examples.simplerpc.server.servlet.GWTSpringServiceLayerDecorator" />
<bean id="defaultExceptionHandler"
class="com.google.web.bindery.requestfactory.server.DefaultExceptionHandler" />
<!-- RequestFactoryServlet bean is scoped as singleton. Injecting custom
SpringServiceLayerDecorator. -->
<bean id="requestFactoryServlet"
class="com.google.web.bindery.requestfactory.server.RequestFactoryServlet"
scope="singleton">
<constructor-arg ref="defaultExceptionHandler" />
<constructor-arg ref="gwtSpringServiceLayerDecorator" />
</bean>
<bean id="gwtSpringEntityLocator"
class="org.spring4gwt.examples.simplerpc.server.servlet.GWTSpringEntityLocator" />
<bean id="gwtSpringServiceLocator"
class="org.spring4gwt.examples.simplerpc.server.servlet.GWTSpringServiceLocator" />
<!-- IMPORTANT NOTE: CustomServletWrappingController is a hacked version
of ServletWrappingController. The servlet class defined here will not be
used. Please see CustomServletWrappingController for more information. -->
<bean id="gwtRequestFactoryController"
class="org.spring4gwt.examples.simplerpc.server.servlet.CustomServletWrappingController">
<property name="servletClass">
<value>com.google.web.bindery.requestfactory.server.RequestFactoryServlet
</value>
</property>
<property name="servletName">
<value>gwtspring</value>
</property>
</bean>
</beans>
EmployeeRequest.java
@Service(locator = GWTSpringServiceLocator.class, value = EmployeeRequest.class)
public interface EmployeeRequest extends RequestContext {
Request<EmployeeProxy> findEmployee(Long id);
InstanceRequest<EmployeeProxy, Void> persist();
}
EmployeeProxy .java
@ProxyFor(value = EmployeeDTO.class, locator = GWTSpringEntityLocator.class)
public interface EmployeeProxy extends EntityProxy {
String getEmployeeName();
String getEmployeeSurname();
Long getEmployeeId();
String getJob();
void setEmployeeName(String employeeName);
void setEmployeeSurname(String employeeSurname);
void setJob(String job);
void setEmployeeId(long employeeId);
}
EmployeeDTO.java
@Entity
@Table(name = "EMPLOYEE")
public class EmployeeDTO implements java.io.Serializable {
private static final long serialVersionUID = 7440297955003302414L;
@Id
@Column(name="employee_id")
private long employeeId;
@Column(name="employee_name", nullable = false, length=30)
private String employeeName;
@Column(name="employee_surname", nullable = false, length=30)
private String employeeSurname;
@Column(name="job", length=50)
private String job;
public EmployeeDTO() {
}
public EmployeeDTO(int employeeId) {
this.employeeId = employeeId;
}
public EmployeeDTO(long employeeId, String employeeName, String employeeSurname,
String job) {
this.employeeId = employeeId;
this.employeeName = employeeName;
this.employeeSurname = employeeSurname;
this.job = job;
}
public long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(long employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public String getEmployeeSurname() {
return employeeSurname;
}
public void setEmployeeSurname(String employeeSurname) {
this.employeeSurname = employeeSurname;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
}
EmployeeService.java
public interface EmployeeService {
public EmployeeDTO findEmployee(long employeeId);
public void persist(EmployeeDTO employeeDTO);
}
EmployeeServiceImpl.java
@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService{
@Autowired
private EmployeeDAO employeeDAO;
@PostConstruct
public void init() throws Exception {
}
@PreDestroy
public void destroy() {
}
public EmployeeDTO findEmployee(long employeeId) {
return employeeDAO.findById(employeeId);
}
@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public void persist(EmployeeDTO employeeDTO) {
if(employeeDTO == null) {
employeeDAO.persist(employeeDTO);
}
}
}
In my onModuleLoad method where I have the event for a button click on the page I am doing this
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
Request<Void> createReq = request.persist().using(newEmployee);
requestFactory.employeeRequest().findEmployee(employeeId).fire(
new Receiver<EmployeeProxy>() {
@Override
public void onSuccess(EmployeeProxy employee) {
System.out.println(employee.getEmployeeId());
dialogBox.setText("Remote Procedure Call");
serverResponseLabel.removeStyleName("serverResponseLabelError");
serverResponseLabel.setHTML("OK");
dialogBox.center();
closeButton.setFocus(true);
}
});
The call for persist using request does not do anything. And the call to findEmployee throws a null pointer exception.
The locators I am using are attached in the mail.
Please help me resolve this.
Thanks & Regards,
Kishore
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment