Share on Google+Share on Google+

naveenkumar
validation
0 Answer(s)      5 years ago
Posted in : Spring

hello sir i tried to store emp details in database from form using spring ,hibernate and jsp

my all classes and jsp pages are pasted here when i try to validate my form its says invalid property'validater of ur controller class ....ple for this example ple write validater class and bean config file its very usefull me,,, i am new no spring.

userFormjsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

Registration Page

<table>

    <tr>

        <td>User Name :</td>

        <td><form:input path="name" /></td>

    </tr>

    <tr>

        <td>Password :</td>

        <td><form:password path="password" /></td>

    </tr>

    <tr>

        <td>Gender :</td>

        <td><form:radiobutton path="gender" value="M" label="M" /> <form:radiobutton

            path="gender" value="F" label="F" /></td>

    </tr>

    <tr>

        <td>Country :</td>

        <td><form:select path="country">

            <form:option value="0" label="Select" />

            <form:option value="India" label="India" />

            <form:option value="USA" label="USA" />

            <form:option value="UK" label="UK" />

        </form:select></td>

    </tr>

    <tr>

        <td>About you :</td>

        <td><form:textarea path="aboutYou" /></td>

    </tr>

    <tr>

        <td>Community :</td>

        <td><form:checkbox path="community" value="Spring"

            label="Spring" /> <form:checkbox path="community" value="Hibernate"

            label="Hibernate" /> <form:checkbox path="community" value="Struts"

            label="Struts" /></td>

    </tr>

    <tr>

        <td></td>

        <td><form:checkbox path="mailingList"

            label="Would you like to join our mailinglist?" /></td>

    </tr>

    <tr>

        <td colspan="2"><input type="submit" value="Register"></td>

    </tr>

</table>

<table cellpadding="5">

    <tr class="even">

        <th>Name</th>

        <th>Gender</th>

        <th>Country</th>

        <th>About You</th>

    </tr>

    <c:forEach items="${userList}" var="user" varStatus="status">

        <tr class="<c:if test="${status.count % 2 == 0}">even</c:if>">

            <td>${user.name}</td>

            <td>${user.gender}</td>

            <td>${user.country}</td>

            <td>${user.aboutYou}</td>

        </tr>

    </c:forEach>

</table>

UserDAO.java package com.vaannila.dao;

import java.util.List;

import com.vaannila.domain.User;

public interface UserDAO {

public void saveUser(User user) ;

public List<User> listUser() ;

} UserDAOimpl.java package com.vaannila.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.vaannila.domain.User;

public class UserDAOImpl implements UserDAO {

private HibernateTemplate hibernateTemplate;



public void setSessionFactory(SessionFactory sessionFactory) {

    this.hibernateTemplate = new HibernateTemplate(sessionFactory);

}



@Override

public void saveUser(User user) {

    hibernateTemplate.saveOrUpdate(user);

}



@Override

@SuppressWarnings("unchecked")

public List<User> listUser() {

    return hibernateTemplate.find("from User");

}

}

User.java package com.vaannila.domain;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.Table;

@Entity

@Table(name="USER")

public class User {

private Long id;

private String name;

private String password;

private String gender;

private String country;

private String aboutYou;

private String[] community;

private Boolean mailingList;



@Id

@GeneratedValue

@Column(name="USER_ID")

public Long getId() {

    return id;

}

public void setId(Long id) {

    this.id = id;

}



@Column(name="USER_NAME")

public String getName() {

    return name;

}

public void setName(String name) {

    this.name = name;

}



@Column(name="USER_PASSWORD")

public String getPassword() {

    return password;

}

public void setPassword(String password) {

    this.password = password;

}



@Column(name="USER_GENDER")

public String getGender() {

    return gender;

}

public void setGender(String gender) {

    this.gender = gender;

}



@Column(name="USER_COUNTRY")

public String getCountry() {

    return country;

}

public void setCountry(String country) {

    this.country = country;

}



@Column(name="USER_ABOUT_YOU")

public String getAboutYou() {

    return aboutYou;

}

public void setAboutYou(String aboutYou) {

    this.aboutYou = aboutYou;

}



@Column(name="USER_COMMUNITY")

public String[] getCommunity() {

    return community;

}

public void setCommunity(String[] community) {

    this.community = community;

}



@Column(name="USER_MAILING_LIST")

public Boolean getMailingList() {

    return mailingList;

}

public void setMailingList(Boolean mailingList) {

    this.mailingList = mailingList;

}

} UserController.java

package com.vaannila.web;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;

import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.vaannila.dao.UserDAO;

import com.vaannila.domain.User;

public class UserController extends MultiActionController {

private UserDAO userDAO;



public void setUserDAO(UserDAO userDAO) {

    this.userDAO = userDAO;

}



public ModelAndView add(HttpServletRequest request,

        HttpServletResponse response, User user) throws Exception {

    userDAO.saveUser(user);

    return new ModelAndView("redirect:list.htm");

}



public ModelAndView list(HttpServletRequest request,

        HttpServletResponse response) throws Exception {

    ModelMap modelMap = new ModelMap();

    modelMap.addAttribute("userList", userDAO.listUser());

    modelMap.addAttribute("user", new User());

    return new ModelAndView("userForm", modelMap);

}

} dispatcher-servlet.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">



<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />



<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>

    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>

    <property name="username" value="sa"/>

    <property name="password" value=""/>

</bean>



<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

    <property name="dataSource" ref="myDataSource" />

    <property name="annotatedClasses">

        <list>

            <value>com.vaannila.domain.User</value>

        </list>

    </property>

    <property name="hibernateProperties">

        <props>

            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>

            <prop key="hibernate.show_sql">true</prop>

            <prop key="hibernate.hbm2ddl.auto">create</prop>

        </props>

    </property>

</bean>



<bean id="myUserDAO" class="com.vaannila.dao.UserDAOImpl">

    <property name="sessionFactory" ref="mySessionFactory"/>

</bean>



<bean name="/user/*.htm" class="com.vaannila.web.UserController" >

    <property name="userDAO" ref="myUserDAO" />

</bean>

Web.xml

SpringExample17

    <servlet-name>dispatcher</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

    <servlet-name>dispatcher</servlet-name>

    <url-pattern>*.htm</url-pattern>

</servlet-mapping>

<welcome-file-list>

    <welcome-file>redirect.jsp</welcome-file>

</welcome-file-list>

for this i need validation sir modified dispatcher servlet xml file also ple help me it s very useful for me

redirect.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% response.sendRedirect("user/list.htm"); %>

Ads

View Answers









Related Tutorials/Questions & Answers:
validation
validation  validation
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
Advertisements
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
form validation
form validation  how the form validation is done in jsf form using javaScript
NSURL Validation
NSURL Validation  How to validate a NSURL string using special character validation
validation query
validation query  where I should kept properties file inside struts Web application
Validation - Struts
Validation  what is the best way to use validation in Struts?either "validation.xml" or JavaScript
Validation of datepicker
Validation of datepicker  I have a datepicker in my JSp...the seleted dates are put in a text box. I want the alert the user from selecting future... a future date is entered..How to do this validation in javascript or jsp
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
Form Validation
Form Validation  Java script validation for checking special characters and white spaces and give an alert.Please help me urgent Thanks in advance
date validation
date validation  sir, pls provide date validation code in javascript..we want to include it into our master form..   Please visit the following link: http://www.roseindia.net/mysql/datevalidation.shtml
validation - Framework
validation  how to validate the action forms in struts? could you please explain how cross validation is done for date?  You go the following url: http://www.roseindia.net/struts/struts-login-form.shtml
Struts validation
Struts validation  I want to put validation rules on my project.But after following all the rules I can't find the result. I have extended... validation rules,put the plugins inside strutsconfig.xml, put the html:errors tag
Validation - Struts
Validation  How can i use validation framework i don't understand am...; Hi friend, Phone validation using javaScript function... return true; } Phone Validation
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try to put string values its not allowing to do tht it gives us message its right
Tutorials   
Java Spring Hibernate Struts Training spring inteview question You Spring Project is not running java lang incompatibleclasschangeerror quartz spring - Error resolved exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined The import javax.validation cannot be resolved java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence Solving java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean issue What is the maven dependency for spring batch? Hibernate Session Attribute java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource Testing spring with junit and mock testing in Spring MVC, i would like to download my Mysql database table in pdf,msword,excel formats. java.lang.NoClassDefFoundError: org/hibernate/engine/FilterDefinition error package org.springframework.scheduling.quartz does not exist jquery dependency dropdown box in spring hibernate my sql Server side validation on dynamically generated fields from more than one table on spring framework. What are the new features of Spring 4.1? Append Arguments to the URL quartz schedular in spring mvc Where to download spring framework zip file? Integrating spring 4 with hibernate 4 Learn spring Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations Spring 4 features I need Spring 2.5 example. Please point me towards a good Spring transactional tutorial Could anyone point me towards some good Spring tutorials, Please? What is Spring framework? Spring and hibernate based Online Shopping project with source code How to populate collection like map with annotation in mybatis? Spring Abstraction with Redis Spring framework How to insert and retreive an image in mysql database using spring mvc framework??? CRUD operations in spring mvc 2.5 meenakshi Meenakshi how many scenarios is having to developing web based application by using spring mvc. getting voucherPin parent and child dropdown Spring 3 Spring 3 MVC Login Form Example with Database MySql What is Spring Integration? How to configure Spring using Annotation What is Spring IOC Container ? What is difference between singleton and prototype bean? What are the differences between EJB and Spring What is Spring's JdbcTemplate ?

Ads

 
Advertisement null

Ads