• 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

struts validator

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using struts validator for some feilds on my jsp.
I have a action form in which there is a collection (array) as the member variable.
I want to make one of member variable of the array class as mandatory.
I get a null pointer excetion if the collection (array) is null.
I want to stop the validation when the data is null(when the screen is loaded for the first time)
Please help
Nitin
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Initialize your field to a zero-length array, do the same thing in the form's reset() method.
To handle the first-time display, I usually check if a specific action came in with the request (I map all my submit buttons to a property called 'action') so my check in validate() is usually:
if (action == null) return null;
If I have many conditions to check, I'll pull those conditions out to a query method so I can write something like
if (skipValidate()) return null;
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic