You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hartmut Bernecker <h....@dhw.de> on 2001/07/18 11:55:59 UTC
Displaying errors when validating forms (ActionErrors)
Hallo,
I have a problem to display ActionErrors. I use the validate-Method to
validate forms, like that:
------------------------------
public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
ActionErrors errors = new ActionErrors();
if (iBenutzer == null || iBenutzer.length() < 1) {
errors.add("benutzungsname", new
ActionError("error.login.benutzername.required"));
}}
------------------------------
But when I want to display that error, I can't see anything. Why?????
* errors.header=<ul>
errors.footer=</ul>
error.login.benutzername.required=that is an error ...
is in the property-file! That property-file is available (set in
web.xml)!
* the JSP contains:
<html:errors/>
<html:errors property="benutzungsname"/>
Who can help me?!
What is wrong??
Re: Displaying errors when validating forms (ActionErrors)
Posted by Hartmut Bernecker <h....@dhw.de>.
OK, thank you, I got it!
I don't understand it, but the problems seems to be the place oft the
<html:errors/> tag within the JSP. I placed it at the end of the <body>
element with bad result. When I moved it top to the <body> element it is
ok. May be there is a problem with the html in the jsp-document ...
Do I am allowed to ask another question:
If I want the error-keys not to have in the main ressource-file
(web.xml:)
( ...
<init-param>
<param-name>application</param-name>
<param-value>asim</param-value>
</init-param>
... )
but in another separate file using <html:errors
bundle="asim-form-validation"/>
,where do I have then to deploy the asim-form-validation.properties
File???
TIA
Guus Holshuijsen schrieb:
>
> Hartmut,
>
> I do it at the end of an action's perform() method using the "construction"
> given in my previous reply!
>
> What I describe is only valid if your controller checks for errors itself.
> In case you let Struts handle the validation automatically, I advice you to
> look at the Struts source code.
> The following code snippet is from the Action.java class:
>
> /**
> * The request attributes key under which your action should store an
> * <code>org.apache.struts.action.ActionErrors</code> object, if you
> * are using the corresponding custom tag library elements.
> */
> public static final String ERROR_KEY = "org.apache.struts.action.ERROR";
>
> Concluding: the errors are stored in the request (session?) attribute
> "org.apache.struts.action.ERROR".
>
> Regards,
> Guus
>
> ----- Original Message -----
> From: "Hartmut Bernecker" <h....@dhw.de>
> To: <st...@jakarta.apache.org>
> Sent: Wednesday, July 18, 2001 12:48
> Subject: Re: Displaying errors when validating forms (ActionErrors)
>
> > No, I think I did not!
> > My validate Method looks like that, it returns Errors back to the
> > controller servlet.
> > - Where is the place to save the errors in the request???
> >
> >
> > public ActionErrors validate(ActionMapping pMapping,
> > HttpServletRequest pRequest)
> > {
> > System.out.println("VALIDIERE");
> > ActionErrors errors = new ActionErrors();
> > if (iBenutzer == null || iBenutzer.length() < 1)
> > {
> > errors.add("benutzungsname",
> > new ActionError("error.login.benutzername.required"));
> > }
> > if (iPasswort == null || iPasswort.length() < 1)
> > {
> > errors.add("passwort",
> > new ActionError("error.login.passwort.required"));
> > }
> > if (iSprache == null || iSprache.length() < 2 ||
> > iSprache.equals("blank"))
> > {
> > errors.add("sprache",
> > new ActionError("error.login.passwort.required"));
> > }
> >
> > return errors;
> > }
> >
> >
> >
> > Guus Holshuijsen schrieb:
> > >
> > > Do you save your errors?
> > >
> > > // Report any errors we have discovered
> > > if ( !errors.empty() )
> > > {
> > > saveErrors( request, errors );
> > > }
> > >
> > > Regards,
> > > Guus
> > >
> > > ----- Original Message -----
> > > From: "Hartmut Bernecker" <h....@dhw.de>
> > > To: <st...@jakarta.apache.org>
> > > Sent: Wednesday, July 18, 2001 11:55
> > > Subject: Displaying errors when validating forms (ActionErrors)
> > >
> > > > Hallo,
> > > >
> > > > I have a problem to display ActionErrors. I use the validate-Method to
> > > > validate forms, like that:
> > > >
> > > > ------------------------------
> > > > public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> > > > request) {
> > > > ActionErrors errors = new ActionErrors();
> > > > if (iBenutzer == null || iBenutzer.length() < 1) {
> > > > errors.add("benutzungsname", new
> > > > ActionError("error.login.benutzername.required"));
> > > > }}
> > > > ------------------------------
> > > >
> > > > But when I want to display that error, I can't see anything. Why?????
> > > >
> > > > * errors.header=<ul>
> > > > errors.footer=</ul>
> > > > error.login.benutzername.required=that is an error ...
> > > >
> > > > is in the property-file! That property-file is available (set in
> > > > web.xml)!
> > > >
> > > > * the JSP contains:
> > > > <html:errors/>
> > > > <html:errors property="benutzungsname"/>
> > > >
> > > > Who can help me?!
> > > > What is wrong??
> >
--
_________________________________________
Hartmut Bernecker
Dipl.-Wirtschaftsinformatiker (BA)
Electronic Publishing
ASIM(r) - CONTENT MANAGEMENT AT ITS BEST
Druckhaus Waiblingen
Siemenstrasse 10
D-71332 Waiblingen, Germany
Tel.: +49 (0)71 51 / 5 66 - 4 48
Fax: +49 (0)71 51 / 5 66 - 3 23
Mail: mailto:h.bernecker@dhw.de
Web: http://www.dhw.de/
_________________________________________
Re: Displaying errors when validating forms (ActionErrors)
Posted by Guus Holshuijsen <gh...@videtur.nl>.
Hartmut,
I do it at the end of an action's perform() method using the "construction"
given in my previous reply!
What I describe is only valid if your controller checks for errors itself.
In case you let Struts handle the validation automatically, I advice you to
look at the Struts source code.
The following code snippet is from the Action.java class:
/**
* The request attributes key under which your action should store an
* <code>org.apache.struts.action.ActionErrors</code> object, if you
* are using the corresponding custom tag library elements.
*/
public static final String ERROR_KEY = "org.apache.struts.action.ERROR";
Concluding: the errors are stored in the request (session?) attribute
"org.apache.struts.action.ERROR".
Regards,
Guus
----- Original Message -----
From: "Hartmut Bernecker" <h....@dhw.de>
To: <st...@jakarta.apache.org>
Sent: Wednesday, July 18, 2001 12:48
Subject: Re: Displaying errors when validating forms (ActionErrors)
> No, I think I did not!
> My validate Method looks like that, it returns Errors back to the
> controller servlet.
> - Where is the place to save the errors in the request???
>
>
> public ActionErrors validate(ActionMapping pMapping,
> HttpServletRequest pRequest)
> {
> System.out.println("VALIDIERE");
> ActionErrors errors = new ActionErrors();
> if (iBenutzer == null || iBenutzer.length() < 1)
> {
> errors.add("benutzungsname",
> new ActionError("error.login.benutzername.required"));
> }
> if (iPasswort == null || iPasswort.length() < 1)
> {
> errors.add("passwort",
> new ActionError("error.login.passwort.required"));
> }
> if (iSprache == null || iSprache.length() < 2 ||
> iSprache.equals("blank"))
> {
> errors.add("sprache",
> new ActionError("error.login.passwort.required"));
> }
>
> return errors;
> }
>
>
>
> Guus Holshuijsen schrieb:
> >
> > Do you save your errors?
> >
> > // Report any errors we have discovered
> > if ( !errors.empty() )
> > {
> > saveErrors( request, errors );
> > }
> >
> > Regards,
> > Guus
> >
> > ----- Original Message -----
> > From: "Hartmut Bernecker" <h....@dhw.de>
> > To: <st...@jakarta.apache.org>
> > Sent: Wednesday, July 18, 2001 11:55
> > Subject: Displaying errors when validating forms (ActionErrors)
> >
> > > Hallo,
> > >
> > > I have a problem to display ActionErrors. I use the validate-Method to
> > > validate forms, like that:
> > >
> > > ------------------------------
> > > public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> > > request) {
> > > ActionErrors errors = new ActionErrors();
> > > if (iBenutzer == null || iBenutzer.length() < 1) {
> > > errors.add("benutzungsname", new
> > > ActionError("error.login.benutzername.required"));
> > > }}
> > > ------------------------------
> > >
> > > But when I want to display that error, I can't see anything. Why?????
> > >
> > > * errors.header=<ul>
> > > errors.footer=</ul>
> > > error.login.benutzername.required=that is an error ...
> > >
> > > is in the property-file! That property-file is available (set in
> > > web.xml)!
> > >
> > > * the JSP contains:
> > > <html:errors/>
> > > <html:errors property="benutzungsname"/>
> > >
> > > Who can help me?!
> > > What is wrong??
>
Re: Displaying errors when validating forms (ActionErrors)
Posted by Hartmut Bernecker <h....@dhw.de>.
No, I think I did not!
My validate Method looks like that, it returns Errors back to the
controller servlet.
- Where is the place to save the errors in the request???
public ActionErrors validate(ActionMapping pMapping,
HttpServletRequest pRequest)
{
System.out.println("VALIDIERE");
ActionErrors errors = new ActionErrors();
if (iBenutzer == null || iBenutzer.length() < 1)
{
errors.add("benutzungsname",
new ActionError("error.login.benutzername.required"));
}
if (iPasswort == null || iPasswort.length() < 1)
{
errors.add("passwort",
new ActionError("error.login.passwort.required"));
}
if (iSprache == null || iSprache.length() < 2 ||
iSprache.equals("blank"))
{
errors.add("sprache",
new ActionError("error.login.passwort.required"));
}
return errors;
}
Guus Holshuijsen schrieb:
>
> Do you save your errors?
>
> // Report any errors we have discovered
> if ( !errors.empty() )
> {
> saveErrors( request, errors );
> }
>
> Regards,
> Guus
>
> ----- Original Message -----
> From: "Hartmut Bernecker" <h....@dhw.de>
> To: <st...@jakarta.apache.org>
> Sent: Wednesday, July 18, 2001 11:55
> Subject: Displaying errors when validating forms (ActionErrors)
>
> > Hallo,
> >
> > I have a problem to display ActionErrors. I use the validate-Method to
> > validate forms, like that:
> >
> > ------------------------------
> > public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> > request) {
> > ActionErrors errors = new ActionErrors();
> > if (iBenutzer == null || iBenutzer.length() < 1) {
> > errors.add("benutzungsname", new
> > ActionError("error.login.benutzername.required"));
> > }}
> > ------------------------------
> >
> > But when I want to display that error, I can't see anything. Why?????
> >
> > * errors.header=<ul>
> > errors.footer=</ul>
> > error.login.benutzername.required=that is an error ...
> >
> > is in the property-file! That property-file is available (set in
> > web.xml)!
> >
> > * the JSP contains:
> > <html:errors/>
> > <html:errors property="benutzungsname"/>
> >
> > Who can help me?!
> > What is wrong??
Re: Displaying errors when validating forms (ActionErrors)
Posted by Guus Holshuijsen <gh...@videtur.nl>.
Do you save your errors?
// Report any errors we have discovered
if ( !errors.empty() )
{
saveErrors( request, errors );
}
Regards,
Guus
----- Original Message -----
From: "Hartmut Bernecker" <h....@dhw.de>
To: <st...@jakarta.apache.org>
Sent: Wednesday, July 18, 2001 11:55
Subject: Displaying errors when validating forms (ActionErrors)
> Hallo,
>
> I have a problem to display ActionErrors. I use the validate-Method to
> validate forms, like that:
>
> ------------------------------
> public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request) {
> ActionErrors errors = new ActionErrors();
> if (iBenutzer == null || iBenutzer.length() < 1) {
> errors.add("benutzungsname", new
> ActionError("error.login.benutzername.required"));
> }}
> ------------------------------
>
> But when I want to display that error, I can't see anything. Why?????
>
> * errors.header=<ul>
> errors.footer=</ul>
> error.login.benutzername.required=that is an error ...
>
> is in the property-file! That property-file is available (set in
> web.xml)!
>
> * the JSP contains:
> <html:errors/>
> <html:errors property="benutzungsname"/>
>
> Who can help me?!
> What is wrong??
>