• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Spring MVC validator to validate @RequestParam

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I have a form on a JSP:



Where a user is required to enter a valid number for later use as the key of a domain object.

In the matching controller, I would like to use a SpringValidator to do the validation as follows:



Will not allow it because I understand that validators are meant for domain objects.

So in order to get around this, for now, I've used the following:



Where SomethingValidator has a validate method:



And Messages is a simple utility class containing an arraylist of strings.

The above code works, for now, I but I would much rather use a SpringValidator.

Does anyone have any ideas of how I might do this?

I have tried using the id as a Spring model attribute but it doesn't actually belong to a domain object but to no avail. I could use id as part of a model attribute representing the domain object id actually belongs to, but putting all of the object's fields on the form as hidden fields and passing them to the controller seems daft.

On a related matter, is it best to bundle all controller methods for a domain object into one controller, or is it better to factor them into individual controllers where each handles one or more related operations?

I have used the latter approach so far.

Thanks

Martin O'Shea.
 
Greenhorn
Posts: 20
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same issue here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic