You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bailey, Shane C." <SH...@saic.com> on 2003/07/28 21:37:17 UTC
Validation question
I have been using the validator plug-in so long now that I can't remember
how this simple thing works:
In an action I determine that the user (as described in a request parameter)
is not in the DB so I want to return an error message to the user
with the username they entered incorrectly. Here is a code snipet:
Action code:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String nameOfUserToUpd =
request.getParameter("username");
DynaActionForm editUserForm = (DynaActionForm)form;
UpdateUserSession updSession = new
UpdateUserSession(nameOfUserToUpd);
User user = updSession.getUser();
if(user==null)
{
//Add error
errors.add("userName", new
ActionError("errors.userNotFound"));
saveErrors(request, errors);
//Set the form variable because the
username came in from a "GET" not a "POST".
editUserForm.set("userName",
nameOfUserToUpd);
return
(mapping.findForward("userNotFound"));
}
...
}
properties file:
errors.userNotFound='{0}' was not found.
On the page mapped to "userNotFound" it displays as: '{0}' was not found
I thought by having the first parameter to errors.add() with the same name
as an attribute on the form bean it would automatically fill in '{0}' ????
This is way past validation and has nothing to do with what is in
validation.xml so I can't specify arg0 value.
How do I accomplish what I am trying to do?
RE: Validation question
Posted by Yansheng Lin <ya...@isogis.com>.
Try
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.userNotFound",
"userName");
-----Original Message-----
From: Bailey, Shane C. [mailto:SHANE.C.BAILEY@saic.com]
Sent: July 28, 2003 1:37 PM
To: struts-user@jakarta.apache.org
Subject: Validation question
I have been using the validator plug-in so long now that I can't remember
how this simple thing works:
In an action I determine that the user (as described in a request parameter)
is not in the DB so I want to return an error message to the user
with the username they entered incorrectly. Here is a code snipet:
Action code:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String nameOfUserToUpd =
request.getParameter("username");
DynaActionForm editUserForm = (DynaActionForm)form;
UpdateUserSession updSession = new
UpdateUserSession(nameOfUserToUpd);
User user = updSession.getUser();
if(user==null)
{
//Add error
errors.add("userName", new
ActionError("errors.userNotFound"));
saveErrors(request, errors);
//Set the form variable because the
username came in from a "GET" not a "POST".
editUserForm.set("userName",
nameOfUserToUpd);
return
(mapping.findForward("userNotFound"));
}
...
}
properties file:
errors.userNotFound='{0}' was not found.
On the page mapped to "userNotFound" it displays as: '{0}' was not found
I thought by having the first parameter to errors.add() with the same name
as an attribute on the form bean it would automatically fill in '{0}' ????
This is way past validation and has nothing to do with what is in
validation.xml so I can't specify arg0 value.
How do I accomplish what I am trying to do?
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org