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

Validate() in ActionForm ??

Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Hey All,

I have a simple page in which the User accepts an input file and does some bussiness logic. I wanted to have validation in the ActionForm as i want to check for file format, size etc.

I have added the code to the validate method in ActionForm and if there are any errors, I create ActionMessage Object and add them to ActionErrors.

I have <html:errors/> in my JSP so that if there are any problems, errors are displayed and the page does not gets submitted

For some reason, it is not working.

I have validate attribute set to true in the struts-config file. Actually, i can see the code going through the validate method, but then it displays a blank page ( from the URL i see in the page, it seems to be pointing to the struts action link ). If i have a valid file, everything works fine

Any help will be appreciated greatly
Mona Tajik

Joined: Apr 27, 2006
Posts: 11
have you saved the errors?
saveErrors(request, errors);
where errors is ActionErrors and request is HttpServletRequest

and whats your mapping for this?
do you include in the forward
<forward name="has_error" path="/">

check your mapping or post some of your codes...
sun cheng

Joined: Jun 02, 2006
Posts: 17
Omer Dawelbeit

Joined: Jun 09, 2006
Posts: 1
are you using the input attribute in your action tag

sun cheng

Joined: Jun 02, 2006
Posts: 17
Are you include the taglig struts-html.tld
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
sun cheng

Joined: Jun 02, 2006
Posts: 17
do you return errors in your ActionForm?
Periakaruppan Thiagarajan
Ranch Hand

Joined: Jul 26, 2005
Posts: 65

You have not done anything wrong. If the validation ends in success, no issues. If not, the controller will will forward it to JSP. Have you given else where the forward path JSP when the validation fails?

If not, since the controller does not find any matching forward, it will display a blank page.

I agree. Here's the link:
subject: Validate() in ActionForm ??
It's not a secret anymore!