struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yansheng Lin" <yansheng....@isogis.com>
Subject RE: Validation question
Date Mon, 28 Jul 2003 19:58:50 GMT
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


Mime
View raw message