Struts: how to pass error messages in Action under Validator scheme

Discussion in 'Java' started by PC Leung, Jul 7, 2004.

  1. PC Leung

    PC Leung Guest

    My form extends ValidatorForm.
    I add additional checking inside this form,
    in addition to validator.xml and validator-rules.xml.
    It works.

    Now, in Action, I check the existence of record in database.
    If exists, I want to display error message from ApplicationResources.properties
    How can I do it? Thanks.

    if (sPassword == null) {
    return mapping.findForward("success");
    } else {
    // already exists
    // display error message back to addUser.jsp
    }
    return mapping.findForward("addUser");
    PC Leung, Jul 7, 2004
    #1
    1. Advertising

  2. PC Leung

    Murray Guest


    > if (sPassword == null) {
    > return mapping.findForward("success");
    > } else {
    > // already exists
    > // display error message back to addUser.jsp
    > }
    > return mapping.findForward("addUser");


    ActionErrors errors = new ActionErrors(); // or get errors from
    ValidatorForm#validate()
    errors.add("errorName", new
    ActionError("some.property.from.application.resources");
    saveErrors(request, messages);


    <html:errors property="errorName"/>
    Murray, Jul 7, 2004
    #2
    1. Advertising

  3. PC Leung

    Murray Guest


    > if (sPassword == null) {
    > return mapping.findForward("success");
    > } else {
    > // already exists
    > // display error message back to addUser.jsp
    > }
    > return mapping.findForward("addUser");


    ActionErrors errors = new ActionErrors();
    // or get errors from ValidatorForm#validate()
    errors.add("errorName", new
    ActionError("some.property.from.application.resources");
    saveErrors(request, messages);


    <html:errors property="errorName"/>
    Murray, Jul 7, 2004
    #3
  4. PC Leung

    Murray Guest


    > if (sPassword == null) {
    > return mapping.findForward("success");
    > } else {
    > // already exists
    > // display error message back to addUser.jsp
    > }
    > return mapping.findForward("addUser");


    ActionErrors errors = new ActionErrors();
    // or get errors from ValidatorForm#validate()
    errors.add("errorName", new
    ActionError("some.property.from.application.resources");
    saveErrors(request, errors);


    <html:errors property="errorName"/>
    Murray, Jul 7, 2004
    #4
  5. PC Leung

    greenleaf81

    Joined:
    Oct 22, 2008
    Messages:
    1
    Wow I was looking to do the same thing and found this 4 year old thread. I had just forgotten to call saveErrors(..) and was wondering what went wrong.

    Thanks for the answer Murray.
    greenleaf81, Oct 22, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    718
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,043
    rjweytens
    Jun 25, 2004
  3. runescience

    Struts mapping action to action???

    runescience, Feb 6, 2006, in forum: Java
    Replies:
    3
    Views:
    1,805
    runescience
    Feb 7, 2006
  4. vyshu
    Replies:
    1
    Views:
    2,520
    Richard Senior
    Apr 27, 2007
  5. John
    Replies:
    0
    Views:
    842
Loading...

Share This Page