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
posted
0
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
posted
0
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
posted
0
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
posted
0
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?
subject: SimpleFormController and request args validation