struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Thorell <drew.thor...@gmail.com>
Subject Validation Problems
Date Tue, 19 Apr 2005 14:44:25 GMT
Hey all,

I've been trying for some time now to figure out what my problem is
with my Validations not displaying error messages back to the page
from where the request came from. It's a simple login page which
pretty much follows Ted's Struts in Action example.

I'm using a Form which extends ValidatorForm, using the <html:errors
/> tag in my jsp.

If you need anymore code that what's below, let me know.

    public static final String errors_login="<li><font
color=\"red\">Wrong User Name and/or Password</font></li>";
    public static final String errors_userpassequal="<li>Invalid Email
Address.</li>";


    public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
    {
        ActionErrors errors = null;
        errors = super.validate(mapping, request);
        
        if (errors == null) 
        {
            errors = new ActionErrors();
        }
        
        if (username.equals(password))
        {
            errors.add("password", new ActionMessage(Constants.errors_login));
        }
        if (! org.apache.commons.validator.GenericValidator.isEmail(
getusername() ) )
        {
            errors.add("username", new
ActionMessage(Constants.errors_userpassequal));
        }
        return errors;
    }

// Execute Method from my Action which extends just Action:

    public ActionForward execute(ActionMapping mapping, ActionForm
form, HttpServletRequest request,
            HttpServletResponse response) throws IOException, ServletException
    {
        boolean validate = false;

        if (!validate)
        {
            ActionErrors errors = new ActionErrors();
            errors.add(ActionErrors.GLOBAL_MESSAGE, new               
                                                    
ActionMessage(Constants.errors_login) );
            saveErrors(request, errors);
// getInput() just returns to index.jsp where the <html:errors /> tag resides.
            return (new ActionForward(mapping.getInput() ) );
        }
     }

I'm purposely making the whole validation process fail just to get any
error message to display (Which they aren't). I was going to try using
<html:messages> but I'm unsure how to assign the id="" tag and where I
can set the attribute for it.

Thanks for any help in advance, let me know if I can clear anything up.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message