This blog records some ideas, notes, and information of my works and studies in information technology.

Sunday, May 10, 2009

How to set up struts 1.1 message pages

  1. Save your messages in ActionMessages.

    final ActionMessages errors = new ActionMessages();
    errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ControlErrMessage", errMessage));

    a. ActionMessages.GLOBAL_MESSAGE is a special key in ActionMessages mapping, don't change it
    b. ControlErrMessage is the key defined in application.properties
  2. Add ActionMessages Object into HttpServletRequest

    request.setAttribute(Globals.MESSAGE_KEY, errors);

    a. Globals.MESSAGE_KEY is fixed value. It's used in JSP (the id value of html:messages)
  3. Show your message in JSP by using tag

    <html:messages id="message" message="true">
        <bean:write name="message">
    </html:messages>

No comments:

Post a Comment