• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

spring mvc with tiles hibernate validator @valid giving error

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to validate my form using JSR hibernate validator @valid annotation.
My application is configured with spring mvc 3 and tiles 2.
But when i submit the form to validate it given the following error

when submitting the form in createresource.jsp action="submitCreateResource.do"
Ideally it should go to "jspCreateResource" tiles definition and show error messages on createresource.jsp (form page)

But it is giving the following error.

Please help me to validate this from properly.


error

javax.servlet.ServletException: Could not resolve view with name 'error' in servlet with name 'spring'
org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1139)
org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:927)
org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:827)




**spring-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";
xmlns="http://www.springframework.org/schema/p";
xmlns:context="http://www.springframework.org/schema/context";
xmlns:mvc="http://www.springframework.org/schema/mvc";
xmlns:tx="http://www.springframework.org/schema/tx";
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schem...ontext-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">;


<context:annotation-config/>
<mvc:annotation-driven />
<context:component-scan
base-package="com.zoombra.controllers" />

<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBas edViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesV iew
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2 .TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>


<bean
class="org.springframework.web.servlet.handler.Sim pleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="com.zoombra.exception.GenericRuntimeException ">
GenericExceptionPage
</prop>
<prop key="java.lang.Exception">error</prop>
</props>
</property>
</bean>

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/dbconnection.properties</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSes sionFactoryBean">
<property name="dataSource" ref="hbmDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.db.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hib ernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.generate_statistics">${hibernate.ge nerate_statistics}</prop>
<prop key="hibernate.use_sql_comments">${hibernate.use_s ql_comments}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql} </prop>
<prop key="hibernate.use_sql_comments">${hibernate.use_s ql_comments}</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.zoombra.pojo.ResourcePojo</value>
</list>
</property>
</bean>

<bean id="hbmDataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="${jdbc.db.driverClassName}" />
<property name="url" value="${jdbc.db.url}" />
<property name="username" value="${jdbc.db.username}" />
<property name="password" value="${jdbc.db.password}" />
</bean>

<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

</beans>


**tiles.xml**


<tiles-definitions>
<definition name="base.definition"
template="/WEB-INF/jsp/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header1" value="/WEB-INF/jsp/header1.jsp" />
<put-attribute name="header2" value="/WEB-INF/jsp/header2.jsp" />
<put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
</definition>


<definition name="jspCreateResource" extends="base.definition">
<put-attribute name="title" value="Zoombra..." />
<put-attribute name="body" value="/WEB-INF/jsp/CreateResource.jsp" />
</definition>

<definition name="welcome" extends="base.definition">
<put-attribute name="title" value="Zoombra..." />
<put-attribute name="body" value="/WEB-INF/jsp/welcome.jsp" />
</definition>


<definition name="login.definition"
template="/WEB-INF/jsp/loginlayout.jsp">
<put-attribute name="body" value="" />
</definition>

<definition name="login" extends="login.definition">
<put-attribute name="body" value="/WEB-INF/jsp/login.jsp" />
</definition>

<definition name="logout" extends="login.definition">
<put-attribute name="body" value="/WEB-INF/jsp/logout.jsp" />
</definition>

</tiles-definitions>
---------------

Resource pojo
---------------------
public class ResourcePojo {

@NotNull
@NotEmpty (message = "Employee Id can not be blank.")
private int empid;
@NotNull
@NotEmpty (message = "First Name can not be blank.")
@Size(max = 10 , message="First name should be between 1 to 50 Characters")
private String firstname;
@NotEmpty (message = "Last Name can not be blank.")


**Resourcecontroller.java**


@Controller
public class ResourceController {


@RequestMapping(value = "/createresource", method = RequestMethod.GET)
public ModelAndView createResource() {

Map model = new HashMap();
model.put("resource", new ResourcePojo());

return new ModelAndView("jspCreateResource", model);
}

@RequestMapping(value= "/submitCreateResource",method = RequestMethod.POST)
public String processForm(@ModelAttribute(value="resource") @Valid ResourcePojo resource
,BindingResult result,ModelMap model ,HttpSession session){

System.out.println("in processForm line 45");
if(result.hasErrors()){
System.out.println("ERROR");
return "jspCreateResource";
}
return null;
}

}
---------------------------

**createresource.jsp**
----------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form"; prefix="form"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

</head>
<body>
<form:form method="post" commandName="resource"
action="submitCreateResource.do">

<form:errors path="empid" />
<form:errors path="firstname"/>
<form:errors path="lastname"/>

<table >
<tr>
<td >
<h2>Create Resource</h2></td>
</tr>
</table>
<table border="0" >
<tr>
<td><form:label path="empid">Employee Id</form:label>
</td>
<td><form:input size="40" path="empid" />
</td>
</tr>
<tr>
<td><form:label path="firstname">First Name</form:label>
</td>
<td><form:input size="40" path="firstname" />
</td>
</tr>
<tr>
<td><form:label path="lastname">Last Name </form:label>
</td>
<td><form:input size="40" path="lastname" />
</td>
</tr>
<tr>
<td><form:label path="fullname">Full Name</form:label>
</td>
<td ><form:input size="40" path="fullname" />
</td>
</tr>
<tr>
<td><form:label path="dob">Date of Birth</form:label>
</td>
<td><form:input path="dob" />
</td>
</tr>
<tr>
<td><form:label path="companydoj">Company DOJ</form:label>
</td>
<td><form:input path="companydoj" />
</td>
</tr>
<tr>
<td><form:label path="projectdoj">Project DOJ</form:label>
</td>
<td><form:input path="projectdoj" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>

</form:form>
</body>
</html>
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic