Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:error --- validator..

 
Umar Hathab Abdullah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Any updates/thoughts on this question?
Your help would be greatly appreciated.
Thanks.
UMAR
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could change your validate to only add an error when none exist.
Just block each errors.add within a
if (!errors.isEmpty())
 
Umar Hathab Abdullah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,
I am actually using Struts Validator. Can I overwrite the validate method in this case?
UMAR
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic