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

  • #46
    Originally posted by bdontu View Post
    if (null != errors && null != errors.getModel()) {
    //check for existance of errors
    mav.addObject("errorMap",errors.getModel());
    return mav;
    }
    A better way to do this is the following.
    BindingResult errors = getBindingResult(request, yourCommandBean);
    if (errors.hasErrors()) {
    return new ModelAndView(getFormView(), errors.getModel());
    }

    Comment


    • #47
      re:jerry.yan.mj

      Hi jerry.yan.mj,

      I guess it is only possible with SimpleFormController and we are talking about

      MultiActionController

      Can you please tell us more..

      Comment


      • #48
        Originally posted by prande View Post
        Hi jerry.yan.mj,

        I guess it is only possible with SimpleFormController and we are talking about

        MultiActionController

        Can you please tell us more..
        Please do not jump to the conclusion before you actually try it.

        I've been doing this for 3 different projects and it is proven to work fine.

        Comment


        • #49
          My Complete Code demonstrating how to do validation with MultiActionController

          Points to be noted:

          I am using MultiActionController, with InternalPathMethodNameResolver


          ----------------------------------------------------------------------

          my bean class Customer.java

          package domain;

          public class Customer
          {
          String firstName;
          String surName;

          public String getFirstName() {
          return firstName;
          }
          public void setFirstName(String firstName) {
          this.firstName = firstName;
          }
          public String getSurName() {
          return surName;
          }
          public void setSurName(String surName) {
          this.surName = surName;
          }
          }

          -------------------------------------------------------------------------

          my controller CustomerMultiController.java

          package controllers;

          public class CustomerMultiController extends MultiActionController
          {

          BindingResult errors;

          public BindingResult getErrors() {
          return errors;
          }

          public void setErrors(BindingResult errors) {
          this.errors = errors;
          }

          public ModelAndView stage2_or_3Handler(HttpServletRequest request, HttpServletResponse response)
          {
          try
          {
          Customer newCustomer = (Customer)newCommandObject(Customer.class);
          bind(request,newCustomer);
          validate(newCustomer);

          if(errors.hasErrors())
          {

          return new ModelAndView("Stage1_GetCustomerDetails",errors.ge tModel());
          }
          else
          {
          return new ModelAndView("Stage3");
          }
          catch(Exception expObj)
          {
          return new ModelAndView("ShowException");
          }
          }



          protected void bind(HttpServletRequest request, Object command) throws Exception
          {
          ServletRequestDataBinder binder = createBinder(request, command);

          binder.bind(request);

          errors = binder.getBindingResult();
          }


          public void validate(Object command)
          {
          Validator[] validators = getValidators();
          if (validators != null)
          {
          for (int index = 0; index < validators.length; index++)
          {
          Validator validator = validators[index];
          if (validator instanceof CustomerInfoValidator)
          {
          if (((CustomerInfoValidator)validator).supports(comma nd.getClass()))
          ValidationUtils.invokeValidator(validators[index], command, errors);
          }

          else if (validator.supports(command.getClass()))
          ValidationUtils.invokeValidator(validators[index], command, errors);
          }
          }
          }
          }


          -----------------------------------------------------------------------

          my validator CustomerInfoValidator.java

          package validation;
          import org.springframework.validation.Errors;
          import org.springframework.validation.ValidationUtils;
          import org.springframework.validation.Validator;

          import domain.Customer;

          public class CustomerInfoValidator implements Validator
          {
          public boolean supports(Class cls)
          {
          return Customer.class.equals(cls);
          }

          public void validate(Object arg0, Errors arg1)
          {
          //Is fields are empty validation
          ValidationUtils.rejectIfEmpty(arg1, "firstName", "firstName.emptyerror");
          ValidationUtils.rejectIfEmpty(arg1, "surName", "surName.emptyerror");
          }
          }

          ---------------------------------------------------------------------
          here is my messages.properties

          firstName.emptyerror=Enter first name.
          surName.emptyerror=Enter surname.

          -----------------------------------------------------------------------


          my customer.jsp

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

          <form:form action="stage2_or_3.do">
          <table>
          <caption align="left"><font color="green"><b>Tell us about yourself</b></font></caption>
          <tr>
          <td align="left">First Name *</td>
          <td></td>
          <td></td>
          <td></td>
          <td align="left"><form:input path="firstName" maxlength="20" size="27"/></td>
          <td></td>
          <td colspan="2"><form:errors path="firstName" cssClass="errorBox"/></td>
          </tr>
          <tr></tr>
          <tr></tr>

          <!-- Field Surname -->
          <tr>
          <td align="left">Surname *</td>
          <td></td>
          <td></td>
          <td></td>
          <td align="left"><form:input path="surName" maxlength="20" size="27"/></td>
          <td></td>
          <td colspan="2"><form:errors path="surName" cssClass="errorBox"/></td>
          </tr>
          <!-- Submit button 'Next' -->
          <tr></tr>
          <tr></tr>
          <tr></tr>
          <tr>
          <td></td>
          <td></td>
          <td colspan="2">
          <input type="submit" value="Next"/>
          </td>
          </tr>
          </table>

          </form:form>


          </body>
          </html>

          --------------------------------------------------------------------

          finally here is my bean-definition file

          <?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-2.5.xsd">

          <!-- ################################ View Resolver ################################ -->
          <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
          <property name="prefix" value="/WEB-INF/jspfiles/"/>
          <property name="suffix" value=".jsp"/>
          </bean>

          <!-- ################################ Handler Mappings ################################ -->
          <bean class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
          <property name="mappings">
          <value>

          /stage2_or_3.do = customerMultiController


          </value>
          </property>
          </bean>


          <!-- ################################ Controller of this Insurance application ########## -->
          <bean id="customerMultiController" class="controllers.CustomerMultiController">
          <property name="methodNameResolver" ref="internalPathMethodNameResolver"/>
          <property name="validators">
          <list>
          <bean class="validation.CustomerInfoValidator"></bean>
          <bean class="validation.DependentInfoValidator"></bean>
          </list>
          </property>
          </bean>

          <!-- ################################ Defining Validator ################################ -->
          <bean id="customerInfoValidator" class="validation.CustomerInfoValidator"/>
          <!-- ################################ Defining type of the method name resolver used by the controller ########## -->
          <bean id="internalPathMethodNameResolver" class="org.springframework.web.servlet.mvc.multiac tion.InternalPathMethodNameResolver">
          <property name="suffix" value="Handler"/>
          </bean>

          <!-- ################################ Message Source ################################ -->
          <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
          <property name="basename" value="messages"/>
          </bean>
          </beans>

          ----------------------

          I hope this help....Enjoy.....

          regards
          SARAVANAN SIVAJI

          Comment


          • #50
            Can you please check if your form tag contains attribute commandName?

            Comment


            • #51
              Using validators in multiaction controller

              Hi saravanan,
              Your example really worked.. As per your example i hv done changes but still there is some other error occurs.. Below is my codes. please refer and let me know where am i wrong?
              My bean class
              ------------------------
              public class StudRegBean {
              private String username;
              public String getUsername() {
              return username;
              }
              public void setUsername(String username) {
              this.username = username;
              }
              }
              -----------------------------
              my controller class
              ----------------------
              public class regController extends MultiActionController {
              ServletRequestDataBinder binder;
              public ModelAndView saveRegistration( HttpServletRequest request, HttpServletResponse response,StudRegBean studRegBean) throws Exception { ModelAndView mv = new ModelAndView("Registration/studentRegistration");
              bind(request,studRegBean);
              validate(studRegBean);
              System.out.println("in save reg : " + studRegBean.getUsername() );
              if(errors.hasErrors())
              {
              Object[] tmp=errors.getModel().keySet().toArray();

              mv.addObject("username",errors.getModel());
              }
              return mv;
              }
              else
              { mv.addObject("studRegBean",studRegBean);
              return mv;
              }
              }
              BindingResult errors;
              public BindingResult getErrors() {
              return errors;
              }
              public void setErrors(BindingResult errors) {
              this.errors = errors;
              }
              @Override
              protected void bind(HttpServletRequest request, Object command) throws Exception {
              StudRegBean studRegBean=(StudRegBean)command;
              ServletRequestDataBinder binder=createBinder(request, command);
              binder.bind(request);
              errors=binder.getBindingResult();
              }

              public void validate(Object command)
              {
              Validator[] validators = getValidators();
              if (validators != null)
              {
              for (int index = 0; index < validators.length; index++)
              {
              Validator validator = validators[index];
              if (validator instanceof StudRegValidator)
              {
              if (((StudRegValidator)validator).supports(command.ge tClass()))
              ValidationUtils.invokeValidator(validators[index], command, errors);
              }
              else if (validator.supports(command.getClass()))
              ValidationUtils.invokeValidator(validators[index], command, errors);
              }
              }
              }
              }

              ------------------------------------------------------------------------
              My Validator class
              ------------------------------------------
              public class StudRegValidator implements Validator{
              public boolean supports(Class arg0) {
              return arg0.equals(StudRegBean.class);
              }
              public void validate(Object obj, Errors errors) {
              StudRegBean studRegBean=(StudRegBean)obj;
              try{
              if (studRegBean == null) {
              errors.rejectValue("username", "error.login.not-specified", null,"Value required.");
              }
              else{
              if (studRegBean.getUsername()== null || studRegBean.getUsername().trim().length() <= 0) {
              System.out.println("user name null value");
              ValidationUtils.rejectIfEmpty(errors, "username",null,"cannnot be null");
              }
              }
              }
              catch(Exception e){
              System.out.println("error caught in validator");
              e.printStackTrace();
              }
              }
              }
              ----------------------------------------------------------------------
              My Jsp Page
              ---------------------------
              <html><head>
              <script>
              function saveRegistration(){
              document.forms[0].param.value="saveRegistration";
              document.forms[0].submit();
              }
              </script></head>
              <body>
              <form:form action="studReg.htm" commandName="studRegBean">
              <input type="hidden" name="param" />
              <table cellpadding="2" border="1">
              <tr>
              <td class="labels" colspan="2" align="left" ><b>
              Account Details</b>
              </td>
              </tr>
              <tr>
              <td class="labels" align="left">*Username</td>
              <td align="left">
              <form:input path="username"/>
              <form:errors path="username"/>
              </td>
              </tr>
              <tr><td align="center">
              <input type ="button" value="Submit" onclick="saveRegistration()"/>
              <input type ="reset" value="Reset"/>
              <input type ="button" value="Cancel"/>
              </td></tr>
              </table>
              </form:form>
              </body>
              </html>
              -----------------------------------------------------------------------
              Finally the dispatcher servlet.xml
              -----------------------------------
              <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
              <property name="mappings">
              <props>
              <prop key="index.htm">indexController</prop>
              <prop key="studReg.htm">regController</prop>
              </props>
              </property>
              </bean>
              <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
              prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />
              <bean id="selectMethodResolver" class="org.springframework.web.servlet.mvc.multiac tion.ParameterMethodNameResolver">
              <property name="paramName">
              <value>param</value>
              </property>
              </bean>
              <bean id="regController" class="controllers.regController">
              <property name="methodNameResolver">
              <ref bean="selectMethodResolver"/>
              </property>
              <property name="validators">
              <ref bean="studRegValidator"/>
              </property>
              </bean>

              ----------------------------------------------------------------------
              Error that is displayed is
              --------------------------------------------------
              org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'studRegBean' available as request attribute org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:521)
              org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:409)
              org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:336)
              org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
              org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:167)
              org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:239)
              org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1158)
              org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:900)
              org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:808)
              org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:476)
              org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:441)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
              org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)
              root cause
              java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'studRegBean' available as request attribute
              org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:142)
              org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getBindStatus(AbstractData BoundFormElementTag.java:176)
              org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getPropertyPath(AbstractDa taBoundFormElementTag.java:196)
              org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getName(AbstractDataBoundF ormElementTag.java:147)
              org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.autogenerateId(AbstractDat aBoundFormElementTag.java:134)
              org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.writeDefaultAttributes(Abs tractDataBoundFormElementTag.java:123)
              org.springframework.web.servlet.tags.form.Abstract HtmlElementTag.writeDefaultAttributes(AbstractHtml ElementTag.java:379)
              org.springframework.web.servlet.tags.form.InputTag .writeTagContent(InputTag.java:139)
              org.springframework.web.servlet.tags.form.Abstract FormTag.doStartTagInternal(AbstractFormTag.java:90 )
              org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag.java:7 7)
              org.apache.jsp.WEB_002dINF.jsp.Registration.studen tRegistration_jsp._jspx_meth_form_005finput_005f0( studentRegistration_jsp.java:649)
              org.apache.jsp.WEB_002dINF.jsp.Registration.studen tRegistration_jsp._jspService(studentRegistration_ jsp.java:318)
              org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
              org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:373)
              org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:336)
              org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
              org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:167)
              org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:239)
              org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1158)
              org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:900)
              org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:808)
              org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:476)
              org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:441)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
              org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)
              -------------------------------------------------------------------------

              My target is to show the errors beside the textboxes that are empty..
              Please refer it and let me know where am i wrong.
              Thanks for you reply..
              Thanks & Regards
              Levis[/LEFT][/CENTER][/LEFT][/LEFT]

              Comment


              • #52
                Hi prande

                Hi prande,

                your question,

                Can you please check if your form tag contains attribute commandName?


                my answer,

                No. My form tag does not contain attribute commandName. I skipped that attribute.

                Because,

                Since MultiActionController handles multiple requests, that is, since it can handle multiple forms, I made the commandName as default name.

                The default command name for MultiActionController is 'command'

                You need not worry about the command name.

                Refer the following scenario,

                Assume that, you have a jsp page called customer.jsp containing fristname and lastname as fields. And assume that you have bean class Customer.java with 2 fields firstname and lastname, along with getters and setters. And again assume that when I click the submit button in customer.jsp, the following things should be done,

                1. the customer.jsp form should be validated
                2. once there is no errors, it should go to success.jsp
                3. if there is errors in the form fields in customer.jsp, I should display the same in customer.jsp

                In ur controller which extends MultiActionController, assume that you methodhandler for customer.jsp, there, you have to give like this,

                Customer newCustomer = (Customer)newCommandObject(Customer.class);


                if errors, display the same page as (refer my reply #49)

                return new ModelAndView("customer",errors.getModel());

                Here is another scenario,

                Assume that, you want to display a new view (customerform.jsp) from home.jsp

                You may have methodhandler for handling the home.jsp request right? there you should write like the following

                return new ModelAndView("customerform", "command", newCommandObject(Customer.class));

                NOTE:
                If u see the above line, I used the default command name. It is better to have the default command name.

                Suppose, If ur multiactioncontroller handles more than one form, use default command name for all. for example, to return inventoryform.jsp once I click the submit button in customerform.jsp, use the same as,


                return new ModelAndView("inventoryform", "command", newCommandObject(Inventory.class));


                I hope I have done something useful. Let me know if anyone have any opinion.

                Enjoy,
                SARAVANAN SIVAJI
                Last edited by saravanansivaji; Jul 1st, 2009, 06:42 AM.

                Comment


                • #53
                  validators in multiaction controller

                  Originally posted by saravanansivaji View Post
                  Hi prande,

                  your question,

                  Can you please check if your form tag contains attribute commandName?


                  my answer,

                  No. My form tag does not contain attribute commandName. I skipped that attribute.

                  Because,

                  Since MultiActionController handles multiple requests, that is, since it can handle multiple forms, I made the commandName as default name.

                  The default command name for MultiActionController is 'command'

                  You need not worry about the command name.

                  Refer the following scenario,

                  Assume that, you have a jsp page called customer.jsp containing fristname and lastname as fields. And assume that you have bean class Customer.java with 2 fields firstname and lastname, along with getters and setters. And again assume that when I click the submit button in customer.jsp, the following things should be done,

                  1. the customer.jsp form should be validated
                  2. once there is no errors, it should go to success.jsp
                  3. if there is errors in the form fields in customer.jsp, I should display the same in customer.jsp

                  In ur controller which extends MultiActionController, assume that you methodhandler for customer.jsp, there, you have to give like this,

                  Customer newCustomer = (Customer)newCommandObject(Customer.class);


                  if errors, display the same page as (refer my reply #49)

                  return new ModelAndView("customer",errors.getModel());

                  Here is another scenario,

                  Assume that, you want to display a new view (customerform.jsp) from home.jsp

                  You may have methodhandler for handling the home.jsp request right? there you should write like the following

                  return new ModelAndView("customerform", "command", newCommandObject(Customer.class));

                  NOTE:
                  If u see the above line, I used the default command name. It is better to have the default command name.

                  Suppose, If ur multiactioncontroller handles more than one form, use default command name for all. for example, to return inventoryform.jsp once I click the submit button in customerform.jsp, use the same as,


                  return new ModelAndView("inventoryform", "command", newCommandObject(Inventory.class));

                  I hope I have done something useful. Let me know if anyone have any opinion.

                  Enjoy,
                  SARAVANAN SIVAJI

                  Hi Saravanan,
                  Did you went through my code that i had sent in the post. I am waiting for ur reply

                  Regards
                  Levis

                  Comment


                  • #54
                    Hi levis

                    Hi levis,

                    do the following changes,

                    1. in ur jsp page,

                    <form:form action="studReg.htm" commandName="studRegBean">

                    remove the attribute commandName,

                    <form:form action="studReg.htm">


                    2. in ur controller class,

                    you have the following method right?

                    public ModelAndView saveRegistration( HttpServletRequest request, HttpServletResponse response,StudRegBean studRegBean)


                    remove the 3rd argument, and do the following changes

                    public ModelAndView saveRegistration( HttpServletRequest request, HttpServletResponse response)
                    {
                    try
                    {
                    // do your process here
                    }
                    catch(Exception expObj)
                    {
                    HttpSession session = request.getSession();
                    session.setAttribute("expInformation", expObj);
                    return new ModelAndView("ShowException");
                    //how u r handling the exception, is up to you
                    }
                    }



                    3. In ur controller class,

                    In the same saveRegistration method, you the following right?

                    bind(request,studRegBean);

                    include the following line before bind(request,command) method,

                    StudRegBean studRegBean = (StudRegBean)newCommandObject(StudRegBean.class);
                    bind(request,studRegBean)


                    I hope this help,

                    let me know if u have problem,

                    Enjoy,
                    SARAVANAN SIVAJI
                    Last edited by saravanansivaji; Jul 1st, 2009, 05:48 AM.

                    Comment


                    • #55
                      validators in multiaction controller

                      Originally posted by saravanansivaji View Post
                      Hi levis,

                      do the following changes,

                      1. in ur jsp page,

                      <form:form action="studReg.htm" commandName="studRegBean">

                      remove the attribute commandName,

                      <form:form action="studReg.htm">


                      2. in ur controller class,

                      you have the following method right?

                      public ModelAndView saveRegistration( HttpServletRequest request, HttpServletResponse response,StudRegBean studRegBean)


                      remove the 3rd argument, and do the following changes

                      public ModelAndView saveRegistration( HttpServletRequest request, HttpServletResponse response)
                      {
                      try
                      {
                      // do your process here
                      }
                      catch(Exception expObj)
                      {
                      HttpSession session = request.getSession();
                      session.setAttribute("expInformation", expObj);
                      return new ModelAndView("ShowException");
                      //how u r handling the exception, is up to you
                      }
                      }



                      3. In ur controller class,

                      In the same saveRegistration method, you the following right?

                      bind(request,studRegBean);

                      include the following line before bind(request,command) method,

                      StudRegBean studRegBean = (StudRegBean)newCommandObject(StudRegBean.class);
                      bind(request,studRegBean)


                      I hope this help,

                      let me know if u have problem,

                      Enjoy,
                      SARAVANAN SIVAJI


                      Hi Saravanan,
                      Thnx for ur reply.. I changed the code as u told. but still there is an error..
                      error is as follows
                      ---
                      org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
                      org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:521)
                      org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:409)

                      ---

                      now it says that binding is not with command..

                      waiting for ur reply

                      Thanks and regards
                      levis

                      Comment


                      • #56
                        Hi saravanansivaji,

                        Thanks for your last post It really helped me ..

                        I was doing mistake near following statment by not taking newCommandObject

                        Customer newCustomer = (Customer)newCommandObject(Customer.class);

                        Is it possible to validate nested property using same strategy?
                        Last edited by prande; Jul 1st, 2009, 06:31 AM.

                        Comment


                        • #57
                          Hi levis

                          Hi levis,

                          Do the following changes too, I forget to mention the following,

                          you have the following code in ur handler method in controller class right?

                          ModelAndView mv = new ModelAndView("Registration/studentRegistration");

                          if(errors.hasErrors())
                          {
                          Object[] tmp=errors.getModel().keySet().toArray();

                          mv.addObject("username",errors.getModel());
                          }
                          return mv;
                          }
                          else
                          { mv.addObject("studRegBean",studRegBean);
                          return mv;
                          }



                          Now,

                          change the following line, from
                          mv.addObject("username",errors.getModel());

                          to
                          mv.addObject("command",errors.getModel());

                          And, also in else part, change the following line, from

                          mv.addObject("studRegBean",studRegBean);

                          to


                          mv.addObject("command",studRegBean);

                          ----------------------------------------------------------------------------------------------------------
                          NOTE:

                          Have a look on the following link before u proceed


                          http://forum.springsource.org/showpo...5&postcount=52
                          ----------------------------------------------------------------------------------------------------------
                          Hope I am directing you in correct way. Let me know, if u have problem still

                          enjoy coding,
                          SARAVANAN SIVAJI
                          Last edited by saravanansivaji; Jul 1st, 2009, 06:42 AM.

                          Comment


                          • #58
                            Hi prande

                            hi prande,

                            ur question,

                            Is it possible to validate nested property using same strategy?

                            my friend,

                            Could u post ur sample code containing the nested property?

                            so that, its easy for me to exactly tell u the solution.

                            regards,
                            SARAVANAN SIVAJI

                            Comment


                            • #59
                              Originally posted by saravanansivaji View Post
                              Hi levis,

                              Do the following changes too, I forget to mention the following,

                              you have the following code in ur handler method in controller class right?

                              ModelAndView mv = new ModelAndView("Registration/studentRegistration");

                              if(errors.hasErrors())
                              {
                              Object[] tmp=errors.getModel().keySet().toArray();

                              mv.addObject("username",errors.getModel());
                              }
                              return mv;
                              }
                              else
                              { mv.addObject("studRegBean",studRegBean);
                              return mv;
                              }



                              Now,

                              change the following line, from
                              mv.addObject("username",errors.getModel());

                              to
                              mv.addObject("command",errors.getModel());

                              And, also in else part, change the following line, from

                              mv.addObject("studRegBean",studRegBean);

                              to


                              mv.addObject("command",studRegBean);

                              ----------------------------------------------------------------------------------------------------------
                              NOTE:

                              Have a look on the following link before u proceed


                              http://forum.springsource.org/showpo...5&postcount=52
                              ----------------------------------------------------------------------------------------------------------
                              Hope I am directing you in correct way. Let me know, if u have problem still

                              enjoy coding,
                              SARAVANAN SIVAJI

                              Hi Saravanan,
                              Thanx for your prompt replies, I am realy enjoying the coding but real enjoyment will be when it is succeeded.. and still it didn't. I hv done modification as u said.. but the following error occurs

                              org.apache.jasper.JasperException: org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'username' of bean class [java.util.HashMap]: Bean property 'username' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
                              org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:521)
                              org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:415)
                              org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:336)
                              org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
                              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
                              org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:167)
                              org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:239)
                              org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1158)
                              org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:900)
                              org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:808)
                              org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:476)
                              org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:441)
                              javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
                              javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
                              org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)


                              Waiting for your reply

                              Regards
                              levis

                              Comment


                              • #60
                                Hi Levis, sorry for the belated reply

                                hi levis,

                                Have you solved your problem? Do u need any help?

                                Comment

                                Working...
                                X