< Previous | Next >

 

Lesson 8: Display error messages

Use this lesson to learn how to display error messages when an action returns them to the input JSP page.

To use ActionErrors, add a Struts HTML tag to display an error message on the input JSP page. You must also add an input field to the action mapping.

To modify the application to return any bean validation errors to the input JSP page:

  1. In the

    validate method of the DateData class, verify that if the input year is less than 1582, the method will return an error with the

    "pre-gregorian" message.

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    
      ActionErrors errors = new ActionErrors();
      if (year < 1582)
      {
        errors.add("year", new org.apache.struts.action.ActionMessage("pre_gregorian"));
      }

  2. Locate the

    "pre-gregorian" error message in ApplicationResources.properties, and verify that the message matches the following definition:

    pre-gregorian=<li>Date is before 1582, the year the Gregorian calendar began</li>

  3. To specify the target JSP page for the error message, select an input for the action that uses the form bean:

    1. Open your Web diagram.

    2. In the diagram, hold the mouse pointer over the /computeDay node and drag the node connection handle to the input.jsp node.

    3. In the pop-up menu, select

      Action Input.

    Your Web diagram should resemble the following image:

  4. Update the input JSP page to display the error message:

    1. Double-click the input.jsp page to open it in the editor.

    2. From the Struts HTML Tags drawer in the Palette, drag an Errors tag to the location in the page where you want the error message to be displayed.
    Your input JSP page should resemble the following image:

  5. Save and close your input JSP page and your Web diagram.

 

Lesson checkpoint

In this lesson, you created the display for an error message in the input JSP page.

You learned to do these tasks:

< Previous | Next >