• 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

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>
errors.footer=</ul><hr>
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.
 
Sheriff
Posts: 17644
300
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, ...);
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic