• 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

html:error --- validator..

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Any updates/thoughts on this question?
Your help would be greatly appreciated.
Thanks.
UMAR
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic