Page 4 of 8 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 73

Thread: How to do validation using MultiActionController

  1. #31
    Join Date
    Jun 2009
    Posts
    10

    Post 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.....

  2. #32

    Default

    can you post your error?

  3. #33
    Join Date
    Jun 2009
    Posts
    10

    Default 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


    command=com.person.formBean.Person@1fbe88
    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.....

  4. #34

    Default

    Hi,

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

    or

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

  5. #35
    Join Date
    Jun 2009
    Posts
    10

    Default

    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"/>
    </c:forEach>
    </spring:bind>


    But if i use

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

    i'm able to display the following as error messages



    personForm=com.person.formBean.Person@57df5 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,firstName.emptyerror.java.l 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,lastName.emptyerror.java.lang.S 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
    mav.addObject("errorMap",errors.getModel());
    return mav;
    }


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

    <bean id="messageSource"
    class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
    <property name="basenames">
    <list>
    <value>/WEB-INF/resources/person</value>
    </list>
    </property>
    </bean>


    person.properties contains


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

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



    Thanks in advance....

  6. #36
    Join Date
    Jun 2009
    Posts
    10

    Default Error resolved

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


    Thanks for helping me......

  7. #37
    Join Date
    Jun 2009
    Posts
    9

    Unhappy 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 {
    errors.pushNestedPath("ydgElements");
    if(element.getElementTitleC()==null||element.getEl ementTitleC().equals("")){
    errors.reject("error.elementTitleC");
    }
    errors.popNestedPath();
    }
    }


    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 at 02:58 AM.

  8. #38
    Join Date
    Jun 2009
    Posts
    10

    Default

    Hi

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

  9. #39
    Join Date
    Jun 2009
    Posts
    9

    Default

    Controllers Code where validator is getting called

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

    }catch (Exception e) {
    e.printStackTrace();
    }
    return mav;
    }

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

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    <%@ taglib prefix="springform" uri="http://www.springframework.org/tags/form"%>
    <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
    </div>
    <h1 class="guideBuildTitle"><springform:hidden path="ydgElements.elementTitleC"/> <c:out value="${elementBean.ydgElements.elementTitleC}"/></h1><a class="titleEdit" href="#" />Edit Title</a>
    </div>
    <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">
    <h5>Description</h5>
    <springform:input path="ydgElements.elementDescC" />
    <!--
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${ydgElements.elementDescC}"/>"/>
    -->
    </div>


    spring mappings

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

  10. #40
    Join Date
    Jun 2009
    Posts
    10

    Default

    I think u have to use commandName instead of ydgElements...in jsp input path elements

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •