File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes How to do form validation ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to do form validation ?" Watch "How to do form validation ?" New topic

How to do form validation ?

michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
Currently I using ActionForm's validate method to do the validation of the form when submit.Is this the best way to do form validation?
Bellow is my validate method, but ActionError(String)is deprecated.

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (userID == null || userID .trim().equals("")) {
errors.add("userID ",new ActionError("error.user.userID .null"));
return errors;
[ June 02, 2005: Message edited by: michelle W ]

michelle Wang <br />SCJP 1.4
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
Hello Michelle!!

Form validation can be done in two ways:Manaul and Automatic. The one you have done is Manual Validation. Automatic Validation is done by enabling <html:javascript/> in your jsp.

For more details,go thru the following pdf:

Apache Struts:Automatically Validating Input

Hope this will be useful
[ June 02, 2005: Message edited by: bhuvan sundar ]
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
You can do validation using the valaidate method of ActionForm or you can use the Validator. This allows declarative validation.
I agree. Here's the link:
subject: How to do form validation ?
It's not a secret anymore!