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

  • #31
    Pls Help me out

    I got struck with validating form using Multiaction controller...
    i've pasted my code in the above post...

    thanks in advance.....


    • #32
      can you post your error?


      • #33
        Pls help me while displaying errors--Multiaction controller

        Hi Jerry,

        I am not getting any exceptions in the console...but while displaying errors in jsp page...they are not getting displayed properly...

        following are the messages getting diaplyed on jsp Page

        [email protected]
        org.springframework.validation.BindingResult.comma nd=org.springframework.validation.BeanPropertyBind ingResult: 2 errors Error in object 'command': codes [firstName.emptyerror.command,firstName.emptyerror]; arguments []; default message [null] Error in object 'command': codes [lastName.emptyerror.command,lastName.emptyerror]; arguments []; default message [null]

        where Person is the command i'm using and firstName,lastName are properties in that...

        Thanks in advance.....


        • #34

          I want to see ur JSP code containing the properties firstName,lastName.


          Tell me, have u used the following attribute in form tag, commandName="---"


          • #35
            If i use below code for dispalying errors i'm not even getting them displayed in my JSP:

            CODE :

            <spring:bind path="personForm.*">
            <c:forEach items="${errorMessages}" var="errormsg">
            <c:out value="errormsg"/>

            But if i use

            <spring:bind path="personForm.*">
            <c:forEach items="${errorMap}" var="msg">
            <c:out value="${msg}"/>

            i'm able to display the following as error messages

            [email protected] org.springframework.validation.BindingResult.perso nForm=org.springframework.validation.BeanPropertyB indingResult: 2 errors Field error in object 'personForm' on field 'firstName': rejected value []; codes [firstName.emptyerror.personForm.firstName,firstNam e.emptyerror.firstName, ang.String,firstName.emptyerror]; arguments []; default message [First Name should not be Empty!] Field error in object 'personForm' on field 'lastName': rejected value []; codes [lastName.emptyerror.personForm.lastName,lastName.e mptyerror.lastName, tring,lastName.emptyerror]; arguments []; default message [LastName should not be Empty!]

            what i used in controller is:

            if (null != errors && null != errors.getModel()) {
            //check for existance of errors
            return mav;

            and i'm using following code to configure my poperties files in application context xml file

            <bean id="messageSource"
            class=" bleResourceBundleMessageSource">
            <property name="basenames">


            firstName.emptyerror=LastName is required
            lastName.emptyerror=LastName is required

            please lety me know the wrong i need to change my resourcebundle in applicationcontext.xml file????

            Thanks in advance....


            • #36
              Error resolved

              i found where i'm doing mistake....
              now i'm able to get the errors displayed on my jSP page .....

              Thanks for helping me......


              • #37
                How to validate nested properties using Validators (MultiActionController)?

                I'm facing similar problems as member have discussed previously..but there is some difference I'm trying to vaildate nested property..

                My Validate method

                public void validate(Object obj, Errors errors) {
                ElementBean elembean = (ElementBean) obj;
                HuYdgElementsT element = elembean.getYdgElements();
                if (element == null) {
                //errors.rejectValue("Element", "error.Element.not-specified", null,"Value required.");
                } else {
                if(element.getElementTitleC()==null||element.getEl ementTitleC().equals("")){

                Exception Occuring
                org.springframework.web.bind.ServletRequestBinding Exception: Errors binding onto object 'command'; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBinding Result: 1 errors
                Error in object 'command': codes [error.elementTitleC.command,error.elementTitleC]; arguments []; default message [null]

                Please provide some sample code if possible

                Thanks in Advance
                Last edited by prande; Jun 29th, 2009, 02:58 AM.


                • #38

                  paste u r jsp and controller code from where you r calling valiadtor.....


                  • #39
                    Controllers Code where validator is getting called

                    public ModelAndView submitForm(HttpServletRequest httpServletRequest,
                    HttpServletResponse httpServletResponse, ElementBean command) {
          "Entered addElement Method###################");
                    ServletRequestDataBinder binder;
                    ModelAndView mav= null;
                    try {
                    binder = createBinder(httpServletRequest, command);
                    errors = binder.getBindingResult();
                    mav = new ModelAndView("Multi",errors.getModel());
                    mav =new ModelAndView("Multi","elementBean",command);

                    }catch (Exception e) {
                    return mav;

                    Form in the JSPhaven't wrriten anything yet to print errors

                    <%@ taglib prefix="c" uri="" %>
                    <%@ taglib prefix="spring" uri=""%>
                    <%@ taglib prefix="springform" uri=""%>
                    <springform:form name="elementForm" method="post" action="/Univ/Multi.htm?testParam=submitForm" commandName="elementBean">
                    <div id="titleHead">
                    <div id="status">
                    <span class="itemLabel">Status:</span>Active at 2:13 p.m., Tues., May 12, 2009
                    <h1 class="guideBuildTitle"><springform:hidden path="ydgElements.elementTitleC"/> <c:out value="${elementBean.ydgElements.elementTitleC}"/></h1><a class="titleEdit" href="#" />Edit Title</a>
                    <div class="rightColHead"><h5 class="headTitle">Element Attributes</h5><a class="collapse" href="#"></a></div>
                    <div id="attributes">
                    <div id="attribLeftFields">
                    <div class="attribField largeField">
                    <springform:input path="ydgElements.elementDescC" />
                    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${ydgElements.elementDescC}"/>"/>

                    spring mappings

                    <bean name="/Multi.htm" class="com.ui.controllers.TestMultiActionControlle r">
                    <property name="methodNameResolver">
                    <ref bean="paramResolver"/>
                    <property name="elementBO" ref="elementBO"></property>
                    <property name="validators"><list><ref bean="elementFormValidator"/></list></property>
                    Last edited by prande; Jun 29th, 2009, 03:43 AM.


                    • #40
                      I think u have to use commandName instead of jsp input path elements

                      and tell me the type of errors variable u r using....


                      • #41
                        otherwise write the below function and call validator from with the controlelr

                        protected Errors bindObject(HttpServletRequest request,
                        Person personCommand,Validator validator) throws Exception {
                        Errors errors = new BindException(personCommand,
                        if (validator.supports(personCommand.getClass())) {
                        ValidationUtils.invokeValidator(validator, personCommand, errors);
                        logger.error("Errors Count : "+errors.getErrorCount());
                        return errors;

                        i think tis may help u...

                        and plz remove the validtor config from displatcher servlet ..


                        • #42
                          I guess that it will not help me ..

                          my elementBean is the command object which contains ydgElements as property which is another class and it contains the elementTitle

                          still I tried and I got following error

                          LoggingInterceptor::afterThrowing Exception in method: handleRequest
                          Jun 29, 2009 1:20:03 PM org.apache.catalina.core.StandardWrapperValve invoke
                          SEVERE: Servlet.service() for servlet ydg threw exception
                          org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBinding Result: 1 errors
                          Error in object 'command': codes [error.elementTitleC.command,error.elementTitleC]; arguments []; default message [null]
                          at org.springframework.web.bind.ServletRequestDataBin der.closeNoCatch( )

                          even before calling the submitForm method

                          Type of varialbe I'm using

                          BindingResult errors;
                          Last edited by prande; Jun 29th, 2009, 04:04 AM.


                          • #43
                            Originally posted by saravanansivaji View Post
                            I think the code is already available in this thread, given by one of our friend jerry, thanks to him. Anyhow I will repaste the code here

                            The following is my multi action controller,

                            public class MyController extends MultiActionController

                            BindingResult errors; //Declaring errors as instance variable to catch error

                            /** My overidden bind() method */

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

                            /** My validator */

                            public void MyValidator(Object command)
                            /** Invoking validator **/
                            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);

                            /** this is my method handler */

                            public ModelAndView newcontactHandler(HttpServletRequest request, HttpServletResponse response)
                            return new ModelAndView("addcontact",errors.getModel());
                            return new ModelAndView("add-success");


                            I hope this help, If u can't understand let me know...

                            Thnx for your reply, i m sorry i m lilbit late to reply you.. I understood your code but stilll something is missing.. Can you tell me from where are you going to use "newcontactHandler" and moreover cn i hv an overview of bean code and a jsp code so that i cn understand the variable used for binding.
                            Moreover.. Aren't you implementing the validator interface?
                            And are these methods written in the controller classes only?
                            Waiting for your reply
                            Waiting for your reply
                            Last edited by levis; Jun 29th, 2009, 08:30 AM.


                            • #44
                              Bean scope

                              using BindingResult errors as instance variable can have undesirable consequences, if bean scope is not appropriate. A singleton will be shared across all users, so will be the instance variable.


                              • #45
                                re:How to do validation using MultiActionController

                                It will be great if somebody will provide some working sample application with all the files for validation in multiactioncontroller if possible provide validation for nested properties