You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Thorell <dr...@gmail.com> on 2005/04/19 16:44:25 UTC

Validation Problems

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


RE: Validation Problems

Posted by Folashade Adeyosoye <sh...@gmail.com>.
Not sure what the limitations might be, but I found out that worked for me.
Also if you define your form as a DynaValidatorActionForm, you have to cast
them as a DynaValidatorActionForm in our action classes


-----Original Message-----
From: Andrew Thorell [mailto:drew.thorell@gmail.com] 
Sent: Tuesday, April 19, 2005 10:58 AM
To: user@struts.apache.org
Subject: Re: Validation Problems

Thanks for the speedy reply, My time is limited to solve this
particular problem, but I'll definitely look into using
DynaValidatorActionForm. I do have another question though, why would
not using DynaValidatorActionForm prevent my  code from display the
error back to the jsp? Is there a limitation that I'm unaware of with
my current setup?

Thanks again,

Andrew

On 4/19/05, Folashade Adeyosoye <sh...@gmail.com> wrote:
> Try using DynaValidatorActionForm...

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


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


Re: Validation Problems

Posted by Andrew Thorell <dr...@gmail.com>.
Thanks for the speedy reply, My time is limited to solve this
particular problem, but I'll definitely look into using
DynaValidatorActionForm. I do have another question though, why would
not using DynaValidatorActionForm prevent my  code from display the
error back to the jsp? Is there a limitation that I'm unaware of with
my current setup?

Thanks again,

Andrew

On 4/19/05, Folashade Adeyosoye <sh...@gmail.com> wrote:
> Try using DynaValidatorActionForm...

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


RE: Validation Problems

Posted by Folashade Adeyosoye <sh...@gmail.com>.
Try using DynaValidatorActionForm...



-----Original Message-----
From: Andrew Thorell [mailto:drew.thorell@gmail.com] 
Sent: Tuesday, April 19, 2005 10:44 AM
To: Struts Mailing List
Subject: Validation Problems

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


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