• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate() in ActionForm ??

 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
e.g.
<forward name="has_error" path="/action.do">

check your mapping or post some of your codes...
 
sun cheng
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark
 
Omer Dawelbeit
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using the input attribute in your action tag
i.e.
<action
path=""
input=""
validate="true"
/>
 
sun cheng
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you include the taglig struts-html.tld
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
 
sun cheng
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you return errors in your ActionForm?
 
Periakaruppan Thiagarajan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj,

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.

Thanks,
Pk
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic