3

HI am starting to use spring 3 mvc and have run into a problem that don't know how to solve;

I am trying to validate a url @pathvariable using:

public String showGsscFormWithVenueId (@Valid 
        @Pattern(regexp="(0?[1-9]*)",message="venueid.not.number")
        @PathVariable String venueId, BindingResult result, Model model) {

However I am getting an exception saying:

Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!

I've read about it on the internet and it says that bindingresult has to be after your model but my model is the pathVariable.

The only reason that I am using binding result is because I want to show the message="venueid.not.number" on the jsp. Therefore, could you please let me know if there is any other way ?

1 Answer 1

4

If the @PathVariable parameter fails validation, then Spring will add the error to the request's BindingResult automatically, you don't need to do that yourself.

As the error suggests, you can only declare an explicit BindingResult parameter when you're using form-base model objects. It's not intended to be used with @PathVariable.

Sign up to request clarification or add additional context in comments.

1 Comment

@tsunade21: Using standard JSTL <fmt:message> tags. The message key is auto-generated from the field name, I can't remember exactly what it uses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.