IntelliJ Java IDE
The moose likes Spring and the fly likes SimpleFormController and request args validation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "SimpleFormController and request args validation" Watch "SimpleFormController and request args validation" New topic
Author

SimpleFormController and request args validation

Weston Everit
Greenhorn

Joined: Aug 11, 2010
Posts: 4
Hi.

I want handle update operation using SimpleFormController.
URL to this controller looks as follow:

http://example.com/updatesomething.html?id=42

I wonder how to validate on the begining if object with the given id (42) exists, because I want display 404 error page when id is incorrect and stop processing.

Thanks in advance for your answers.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
Howdy, and welcome to JavaRanch!

Personally, I'm not convinced that a 404 is an appropriate reaction to this type of error--it's not that the page doesn't exist, it's that the object being looked up doesn't exist, correct? Or is this for a service and you specifically need a response code?
Weston Everit
Greenhorn

Joined: Aug 11, 2010
Posts: 4
Yes I want to respond properly when the object beeing looked up doesn't exist.
I wonder what is the best, appropriate approach?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
An error message saying what they're looking up doesn't exist. (In my opinion, anyway, depending on the usecase. A 404 indicates something specific, that the page being requested isn't even there. But it is, in this case.)
Weston Everit
Greenhorn

Joined: Aug 11, 2010
Posts: 4
I have to agree that message is probably more appropriate.

Ok but in my controller I override following methods:
- formBackingObject
- onSubmit

In formBackingObject method I try to fetch object by ID and fill in the command object.
The question is... how to handle the situation when ID is invalid and object cannot be fetch?

How can I stop processing or show message that you mentioned above?
 
IntelliJ Java IDE
 
subject: SimpleFormController and request args validation
 
Threads others viewed
How to pass request parameter from SimpleFormController to ParameterizableViewController
how to set getting input from user
using SimpleFormController
Spring *Controller-Servelt.xml
ternary operator
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture