File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes struts validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts validator " Watch "struts validator " New topic

struts validator

Nitin Raodeo

Joined: Jul 27, 2002
Posts: 21
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

1) SCJP 1.4<br />2) SCBCD (EJB 2.0)<br />3) IBM WebSphere Portal<br />4) WSAD (exam 287)
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

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;

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: struts validator
It's not a secret anymore!