jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes problem validating form fields in ActionForm...... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem validating form fields in ActionForm......" Watch "problem validating form fields in ActionForm......" New topic
Author

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

Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
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.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

If you are trying to show errors with
<html:errors />
Then you should use
errors.add(ActionErrors.GLOBAL_ERROR, ...);


Junilu - [How to Ask Questions] [How to Answer Questions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem validating form fields in ActionForm......