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?