• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

problem validating form fields in ActionForm......

Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys , i am very new to struts. So, i am having some funny problems.I have added this method definition into the subclass to ActionForm class, to take care of validation of my login screen,where the username and password are required as usual.(The login DB authentication and access to homepage is working).
I have also added the attribute validate="true" to my action tag in the struts configuration file.
Besides,i have added this to my ApplicationResources.properties file :
errors.header=<h4>Validation Error(s)</h4><ul>
error.name=<li>Enter your name
error.password=<li>Enter your password
// In ActionForm subclass
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

// Check for mandatory data
ActionErrors errors = new ActionErrors();
if (name== null || name.equals("")) {
errors.add("name", new ActionError("error.name"));
if (password== null || password.equals("")) {
errors.add("password", new ActionError("error.password"));

return errors;
But,, when the form was submitted with either of the fields empty,all i saw on the screen is a big dot, which i believe stands for <ul> i've added and besides on viewing the source, i saw <ul></ul> only, no error message.
Question: What am doing wrong ? if the <ul></ul> can be read from the
ApplicationResources.properties , why NOT the error messages.
Al ideas are welcomes.
NOTE: i upgraded from Struts 1.0.2 to 1.1
I have put some system.out messages in the validate() method blocks for name and password and this gets sent to the Tomcat 4.0.2 console.
Posts: 16042
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
If you are trying to show errors with
<html:errors />
Then you should use
errors.add(ActionErrors.GLOBAL_ERROR, ...);
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic