File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes html:error --- validator.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:error --- validator.." Watch "html:error --- validator.." New topic
Author

html:error --- validator..

Umar Hathab Abdullah
Greenhorn

Joined: Jan 23, 2003
Posts: 18
Hi,
I am doing the server side validation using struts in my application. When I submit the form without entering the values for the mandatory fields, All the error messages are printed.
Can I anyone tell me how to display only the first message from ActionErrors using <html:errors> or other methods(Which I suppose I am not aware).
Thanks for your valuable time.
Regards,
Umar
Umar Hathab Abdullah
Greenhorn

Joined: Jan 23, 2003
Posts: 18
Hi,
Any updates/thoughts on this question?
Your help would be greatly appreciated.
Thanks.
UMAR
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

You could change your validate to only add an error when none exist.
Just block each errors.add within a
if (!errors.isEmpty())


A good workman is known by his tools.
Umar Hathab Abdullah
Greenhorn

Joined: Jan 23, 2003
Posts: 18
Hi Marc,
I am actually using Struts Validator. Can I overwrite the validate method in this case?
UMAR
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There IS a property attribute of the html:errors tag but that doesn't sound like what you require. What that does is only list the errors/messages that were created with the name/key equal to property attribute. (The ActionErrors allows for more than one error per name/key.)
That does not allow you to display only the first error received though.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Yeah, you'll have to write your own stuff but you can still use the built-in logic of their validator classes. For instance, have this in your own required validator method:
if(errors.isEmpty() && GenericValidator.isBlankOrNull(selected)){
errors.add(field.getKey(),
Resources.getActionError(request, va, field) );
return false;
}else{
return true;
}
I would think that should work.
[ April 08, 2004: Message edited by: Marc Peabody ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:error --- validator..
 
Similar Threads
Part II/III, what did you use to draw the diagrams?
Absolute path for jsp
Alternate flows -- sequence diagrams
Head First - MiniMiniMusicCmdLine
Getting "Lookup Error Name comp/env/mail not found in context "java:"." error