• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validate() in ActionForm ??

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mark
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you return errors in your ActionForm?
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic