• 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

Not able to validate my JSP

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to use Struts validator framework.I have a JSP Page where I have two dropdowns. Both the dropdowns have some default values. When the user clicks on Submit button , he should not be allowed to go to the next page if he has not selected anything from the two dropdowns.
I am doing something like this but am able to proceed without getting an error message on the JSP Page



TIA,
Priya
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you are using Struts 1.1.
1.0 doesn't have validator support.

Vicky
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Your ActionForm should extend ValidatorForm. If you overwrite the validate method, you will need to make sure that it makes a call to the super.validate method.

2) ApplicationResources is not an xml file. It should look like this:
prompt.reportType =Report Type
prompt.productLine =Product Line

3) You are making the display of messages harder than it should be. All you should need in the jsp is <html:errors/>. If you want the extra formatting, it will handle it for you if you have entries for:
errors.header
errors.footer
errors.prefix AND
errors.suffix
 
Priya Jotwani
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marc for your reply. It seems to be working now . The problem was that I hadn't specified the input attribute in my Struts-config.xml.

But now I have one more problem . I have 4 JSP Pages and one ActionForm class for all these pages. Now I need to validate the input fields of all the 4 JSPs(i.e all the fields are required). Now , if in my Validator.xml, I specify all the fields , it fires all the validations on the very first page(ie. it cribs abt the fields on page 2,3 and 4 as Required). How can i handle such situation ?

TIA,
Priya
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a hidden value for each page.

Then use the validation to check that the page is a certain value to determine if a field is required. You will use requiredif validation for 1.1 or validwhen if you use 1.2.

http://struts.apache.org/userGuide/dev_validator.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic