File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes handling errors vs. warnings in Struts 1.38 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "handling errors vs. warnings in Struts 1.38" Watch "handling errors vs. warnings in Struts 1.38" New topic

handling errors vs. warnings in Struts 1.38

Chuck Emmons

Joined: Jul 17, 2008
Posts: 2

I am writing an application that requires erroneous user input to be a "hard error" for user class A, but only a warning for user class B.

I have searched high and low for how to handle this, and came across the following "best practices" below.

1. To display the error messages of different categories, define these categories such as FATAL, ERROR, WARNING, or INFO, in an interface.

2. In the Action or form-bean class, you can then use the following:
  • errors.add("fatal", new ActionError("....")); or
  • errors.add("error", new ActionError("....")); or
  • errors.add("warning", new ActionError("....")); or
  • errors.add("information", new ActionError("...."));
  • saveErrors(request,errors);

  • 3. To display them according to those categories, use the following code:

    I am assuming that the interface mentioned above would be an interface to the ActionMessages class and that the category definitions would just be static variables in the interface. Is this the case? I need to have a way of determining if the collection contains actual errors at submittal to handle the "hard errors" or just display the warnings.

    Any advise would be greatly appreciated.

    David Newton

    Joined: Sep 29, 2008
    Posts: 12617

    Anything recommending defining constants in an interface should probably be considered outdated, at least in terms of that.

    As far as determining what the collection contains--it seems like you already are, with the messagePresent tag, no? I'm a little confused as to what the actual question is.
    I agree. Here's the link:
    subject: handling errors vs. warnings in Struts 1.38
    It's not a secret anymore!