• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem validating form fields in ActionForm......  RSS feed

Gabriel Fox
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • 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.
Junilu Lacar
Posts: 11435
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to show errors with
<html:errors />
Then you should use
errors.add(ActionErrors.GLOBAL_ERROR, ...);
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!