-
Jun 26th, 2009, 01:56 AM
#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.....
-
Jun 26th, 2009, 07:25 AM
#32
-
Jun 26th, 2009, 08:41 AM
#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
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.....
-
Jun 27th, 2009, 07:17 AM
#34
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="---"
-
Jun 27th, 2009, 10:10 AM
#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"/>
</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....
-
Jun 28th, 2009, 02:30 AM
#36
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......
-
Jun 29th, 2009, 02:55 AM
#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 {
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.
-
Jun 29th, 2009, 03:34 AM
#38
Hi
paste u r jsp and controller code from where you r calling valiadtor.....
-
Jun 29th, 2009, 03:39 AM
#39
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.
-
Jun 29th, 2009, 03:50 AM
#40
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
-
Forum Rules