PDA

View Full Version : two validators for the same controller.



Uppstream
Mar 3rd, 2009, 10:32 AM
hi, I am using spring 2.5 and I want to use two validators for the same controllers, I would also like to have two different model object in the controller. The way it is now, when I just try to call two different validators from two different methods in the same controller one of the validators always give me an error message when an error is discovered. So it seems the validaton still works but the validator can not read the property of the error..or something like that.

The other validator seems to be working fine..

how can I use two validators for the same controller? is it even possible? none of the validators inherit anything, so they are not of a special kind..

thanks beforehand!

br
/Elin

Uppstream
Mar 4th, 2009, 01:42 AM
is there no one who have had this problem before. The error message I am getting when inputing errors in filed. IE when the validator is running is the following:

NestedServletException: Request processing
failed; nested exception is org.springframework.beans.NotReadablePropertyExcep tion: Invalid property
'hourRateEndDate' of bean class [java.util.HashSet]: Bean property 'hourRateEndDate' is not readable
or has an invalid getter method: Does the return type of the getter match the parameter type of the
setter?

dollowed by a lot of different stack traces of course..

no one who has any idea?

thanks again!!

Ta

Uppstream
Mar 4th, 2009, 06:17 AM
now I have managed to solve some of my problems, the initial one showed to have nothing to do with using two validators for the same controller. But now I am stuck again. And I think I have managed to get to the real problem with using two validators for the same controller.

I have two processSubmit that both returns a json view. When trying to validate the second one I run into problems. If I make error input, the controller discoveres it and gets to the error part of the code. However, the result is i still a sucess althoug my model has an error attacked.

The only thing I have come up with so far is that the old status from the previos processSubmit is still active somehow and that the status therefore does not get updated from success to error..

here are the beginnings of my two different processSubmit:


@RequestMapping(method = RequestMethod.POST, value = "/hourRates.htm")
public ModelAndView processSubmitHR(@ModelAttribute("hourRate")
HourRate hourRate,BindingResult result, HashSet<HourRate> hourRateSet, SessionStatus status, ModelMap myModel, HttpServletRequest request){

// get language from cookie
//System.out.println("hourRatesSet in " + hourRatesSet.size());
CookieHandler cookieHandler = new CookieHandler();
Cookie localeCookie = cookieHandler.getCookie(request);

//validate
mHourRateValidator.validate(mAssignmentId, hourRate, mHourRatesSet, result,new Locale(localeCookie.getValue()));
if (result.hasErrors()) {
System.out.println("errors ");
return new ModelAndView("jsonView", myModel);

this one works fine.

the one that doesn't work:

@RequestMapping(method = RequestMethod.POST, value = "/editassignments.htm")
public ModelAndView processSubmit(@ModelAttribute("assignment")
Assignment assignment,BindingResult result, SessionStatus status, ModelMap myModel,
HttpServletRequest request){

// get language from cookie
CookieHandler cookieHandler = new CookieHandler();
Cookie localeCookie = cookieHandler.getCookie(request);
// validate
//System.out.println();
mAssignVal.validate(assignment, result, new Locale(localeCookie.getValue()));
if (result.hasErrors()) {
return new ModelAndView("jsonView", myModel);
}else {


here I get into the if and the model contains the error I want to print, but still the post is a success??!?

I hope very much someone has any ideas, any at all, that I can try!!