Announcement Announcement Module
Collapse
No announcement yet.
Unable to do validation when using ParameterMethodNameResolver Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to do validation when using ParameterMethodNameResolver

    I am using ParameterMethodNameResolver so that the param property value can be set with the name of the method in the controller. But in such cases, HttpServletResponse and HttpServletRequest should be present as arguments for the controller method to be dispatched. Otherwise error will be shown like 'No Handler method found in the class'.

    But on putting the BindingResult as the argument after '@modelAttribute', error is shown like "org.springframework.beans.BeanInstantiationExcept ion: Could not instantiate bean class [org.springframework.validation.BindingResult]: Specified class is an interface."

    Is it possible to use the BindingResult when we use ParameterMethodNameResolver?

    The controller file is personalDetailsController.java
    Code:
    @RequestMapping(value = "action", method = RequestMethod.POST)
    
        public ModelAndView saveMethod(HttpServletRequest request, HttpServletResponse response, 
                 @ModelAttribute("ContactDetailsForm")  ContactDetailsForm con) throws Exception {
            System.out.println("This is save");
            contactService.addContact(con);
            ModelMap model = new ModelMap();
            model.addAttribute("ContactDetailsForm", new ContactDetailsForm());
            return new ModelAndView("contact",model);
        }
    spring-servlet.xml

    Code:
    <?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:util="http://www.springframework.org/schema/util"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx"
        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">
     
         
        <context:annotation-config />
        <context:component-scan base-package="org" />
      
        
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />
              
        <tx:annotation-driven />
        <bean id="transactionManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
              
        <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">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                </props>
            </property>
        </bean> 
        
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="action.htm">action</prop>
                    <prop key="/hello.htm">helloC</prop>
                </props>
            </property>
        </bean>
        
        <bean id="helloC" class="org.controller.personalDetailsController">
            
        </bean>
        
        <bean id="selectMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
            <property name="paramName">
                <value>param</value>
            </property>
        </bean>
        
        <bean id="action" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController">
            <property name="methodNameResolver">
                <ref bean="selectMethodResolver"/>
            </property>
            <property name="delegate">
    
                <ref bean="helloC"/>
    
            </property>
           
        </bean>
       
    </beans>
    Anybody pls help. What should I do to implement the BindingResult inorder to do validation.
    Last edited by s_k_divya; Jun 22nd, 2013, 10:21 AM.
Working...
X