-
Jun 2nd, 2009, 02:09 PM
#11
hi jerry, I am getting same error
hi jerry,
As you suggested, I have tried the following in my handler,
public ModelAndView newcontactHandler(HttpServletRequest request, HttpServletResponse response, Contact contact)
{
try
{
ServletRequestDataBinder binder = createBinder(request, contact);
BindingResult errors = binder.getBindingResult();
if (errors.hasErrors())
{
return new ModelAndView("addcontact");
}
phoneBook.addNewContact(contact);
return new ModelAndView("add-success");
}
catch(Exception expObj)
{
System.out.println(expObj);
return new ModelAndView("add-fail");
}
}
Am I did the one that u have said?
I am ending up with the same error,
----------------------------------------------------------------
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBinding Result: 2 errors
Field error in object 'command' on field 'contactName': rejected value []; codes [contactName.emptyerror.command.contactName,contact Name.emptyerror.contactName,contactName.emptyerror .java.lang.String,contactName.emptyerror]; arguments []; default message [Contact Name should not be Empty!]
Field error in object 'command' on field 'phoneNumber': rejected value []; codes [phoneNumber.emptyerror.command.phoneNumber,phoneNu mber.emptyerror.phoneNumber,phoneNumber.emptyerror .java.lang.String,phoneNumber.emptyerror]; arguments []; default message [Phone Number should not be Empty!]
----------------------------------------------------------------------
-
Jun 2nd, 2009, 02:30 PM
#12
can you post the complete stacktrace?
can you post the complete stacktrace?
-
Jun 2nd, 2009, 02:33 PM
#13
my complete stack Trace
Thank you very much jerry...as I was eagerly waiting for ur replay...here is my complete stack trace
SEVERE: Servlet.service() for servlet phonebook threw exception
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBinding Result: 2 errors
Field error in object 'command' on field 'contactName': rejected value []; codes [contactName.emptyerror.command.contactName,contact Name.emptyerror.contactName,contactName.emptyerror .java.lang.String,contactName.emptyerror]; arguments []; default message [Contact Name should not be Empty!]
Field error in object 'command' on field 'phoneNumber': rejected value []; codes [phoneNumber.emptyerror.command.phoneNumber,phoneNu mber.emptyerror.phoneNumber,phoneNumber.emptyerror .java.lang.String,phoneNumber.emptyerror]; arguments []; default message [Phone Number should not be Empty!]
at org.springframework.web.bind.ServletRequestDataBin der.closeNoCatch(ServletRequestDataBinder.java:121 )
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.bind(MultiActionController.jav a:541)
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.invokeNamedMethod(MultiActionC ontroller.java:470)
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.handleRequestInternal(MultiAct ionController.java:410)
at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
-
Jun 2nd, 2009, 02:36 PM
#14
Hi jerry
Hi jerry,
The following classNoCatch() method is throwing that exception
public void closeNoCatch() throws ServletRequestBindingException {
if (getBindingResult().hasErrors()) {
throw new ServletRequestBindingException(
"Errors binding onto object '" + getBindingResult().getObjectName() + "'",
new BindException(getBindingResult()));
}
}
-
Jun 2nd, 2009, 02:42 PM
#15
this is corrent!
This correct actually.
As you see from the spring source,
/**
* Bind request parameters onto the given command bean
* @param request request from which parameters will be bound
* @param command command object, that must be a JavaBean
* @throws Exception in case of invalid state or arguments
*/
protected void bind(HttpServletRequest request, Object command) throws Exception {
logger.debug("Binding request parameters onto MultiActionController command");
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
if (this.validators != null) {
for (int i = 0; i < this.validators.length; i++) {
if (this.validators[i].supports(command.getClass())) {
ValidationUtils.invokeValidator(this.validators[i], command, binder.getBindingResult());
}
}
}
binder.closeNoCatch();
}
it throws out anyways.
Now the question is how to control this?
The reason I do not have it is because I have my own multiactioncontroller wrapped the spring's mac. In that I override the bind method:
protected void bind(HttpServletRequest request, Object command) throws Exception {
if (logger.isDebugEnabled()) logger.debug("Binding request parameters onto MultiActionController command");
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
BindingResult errors = binder.getBindingResult();
request.setAttribute(BindingResult.MODEL_KEY_PREFI X + getCommandName(command), errors);
String methodName = (String) request.getAttribute(METHOD_ATTRIBUTE_NAME);
Validator[] validators = (isCancelled(request)) ? null : getValidators();
if (validators != null) {
for (int i = 0; i < validators.length; i++) {
Validator v = validators[i];
if (v instanceof BaseValidator) {
if (((BaseValidator)v).supports(command.getClass(), methodName)) {
ValidationUtils.invokeValidator(validators[i], command, errors);
}
} else if (v.supports(command.getClass())) {
ValidationUtils.invokeValidator(validators[i], command, errors);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Data binding errors: " + errors.getErrorCount());
}
if (errors.hasErrors()) {
if (throwExceptionOnBindingError) {
binder.closeNoCatch(); // drastic error
}
}
}
Now, there is a parameter that controls the throwing.
if (errors.hasErrors()) {
if (throwExceptionOnBindingError) {
binder.closeNoCatch(); // drastic error
}
}
All my other mac extends this class, and the property can be configured in the app-servlet.xml.
-
Jun 2nd, 2009, 02:44 PM
#16
no secret now
Since, I have included my source. Maybe I can tell you more about this multiactioncontroller.
You might noticed my validator part. With this, you can assign which validator should be executed when which method is called.
-
Jun 2nd, 2009, 02:47 PM
#17
jerry,
do u want me to override the bind method in my controller?
Could you tell me exactly what I have to do next?
Thanks
-
Jun 2nd, 2009, 02:50 PM
#18
talk to you later as i am at work.
talk to you later as i am at work.
-
Jun 2nd, 2009, 02:55 PM
#19
Thank u very much jerry for ur great job
Thank you jerry for your kind reply. I am waiting for you...
-
Jun 3rd, 2009, 01:38 AM
#20
Successfully Completed
Hi jerry,
My sincere thanks to you. I successfully completed my Validation with MultiActionController.
Thank you for your great job.
Thanks once again for every once support.
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