Skip to content

Support JSR 303 @Valid on @PathVariable [SPR-9840] #14473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Sep 28, 2012 · 2 comments
Closed

Support JSR 303 @Valid on @PathVariable [SPR-9840] #14473

spring-projects-issues opened this issue Sep 28, 2012 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 28, 2012

Neil Laurance opened SPR-9840 and commented

Similar to #11041.

I have a controller with the following:

@Controller
public class BookController {

   @RequestMapping("/books/{isbn}")
   public @ResponseBody Book getBook(@Valid @PathVariable("isbn") Isbn isbn) {
      return bookService.getBook(isbn);
   }

   // thrown when validation fails
   @ExceptionHandler(BindException.class) 
   @ResponseStatus(value = HttpStatus.BAD_REQUEST)
   public void bindException() {}
}

Where I have registered a custom converter:

   <mvc:annotation-driven conversion-service="conversionService" />

   <bean id="conversionService" class="...">
      <property name="converters">
         <set>
            <bean class="common.domain.StringIsbnConverter" />
         </set>
      </property>
   </bean>

When I run this, my validation code annotation is ignored.

However, if I remove @PathVariable, then the code still works, although my IDE warns that 'URI template variable "isbn" is not defined'.

http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#validation-mvc-triggering suggests this should work.


Affects: 3.1.1

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Neil Laurance commented

(Example code should have had an @Autowired BookService instance.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

When you remove the @PathVariable annotation, the argument is treated as a model attribute (i.e. as if it was annotated with @ModelAttribute).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants