I hope you have not set validate="true" for the both the load and submit action mapping
i.e there wld be a action mapping for loading the screen(say load) The validate 
attribute for this action
Be set to false

Then there wld be a action maqpping when to want to validate(say on submit of a button 
- lets call it submitaction). The validate attribute of only this shld be set to true

Thanks,
Satish


-----Original Message-----
From: Lesaint Sébastien [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 14, 2004 1:19 PM
To: Struts Users Mailing List
Subject: Help with validate ActionForm method


Hi,

I'm using ActionForm for one of my pages and I implemented the validate method as 
follow: public ActionErrors validate(ActionMapping mapping,
                               HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();

    if (isFieldEmpty(login)) {
      errors.add("login", new ActionError("loginForm.login.required"));
    }

    if (isFieldEmpty(password)) {
      errors.add("password", new ActionError("loginForm.password.required"));
    }

    if (errors.isEmpty()) {
      if (!isConnected(login, password)) {
        errors.add("login", new ActionError("loginForm.msgs.wrongLoginorPassword"));
      }
    }

    if (!errors.isEmpty()) {
      getLogger().info(this, "Failed attempt to log in : [" + login + "/" + password + 
"] from : " + request.getRemoteHost());
    }
    return (errors);
 }

You can see that I log each time someone fail to log in.
When the validate method returns an empty Error Array, login/password are checked in 
an Action object.

The problem is that I have the following trace in the log when somebody successfully 
log in : 09:26:54,500 INFO  [lex.LoginAction] User logged in [login/pwd] sessionId 
[773BB4634682A159DC680847073E4EC8] from [10.10.10.10] 09:26:54,587 INFO  
[lex.LoginActionForm] Failed attempt to log in : [/] from
: 10.10.10.10

These traces obiviously means that the validate method is called twice, the second 
time the ActionForm having empty fields.

Does anybody know why such a thing would happen ????

Thanks

-- 
Seb'

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to