| Author |
Not able to validate my JSP
|
Priya Jotwani
Ranch Hand
Joined: Oct 30, 2002
Posts: 53
|
|
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
|
 |
vicky kumar
Ranch Hand
Joined: Dec 13, 2002
Posts: 55
|
|
Make sure you are using Struts 1.1. 1.0 doesn't have validator support. Vicky
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4695
|
|
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
|
A good workman is known by his tools.
|
 |
Priya Jotwani
Ranch Hand
Joined: Oct 30, 2002
Posts: 53
|
|
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
Sheriff
Joined: Feb 05, 2003
Posts: 4695
|
|
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
|
 |
 |
|
|
subject: Not able to validate my JSP
|
|
|