wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

handling errors vs. warnings in Struts 1.38

Chuck Emmons
Greenhorn

Joined: Jul 17, 2008
Posts: 2
Hello,

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
    Author
    Rancher

    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.
     
     
    subject: handling errors vs. warnings in Struts 1.38
     
    Similar Threads
    ActionErrors
    ActionMessages & logic:messagesPresent
    problem with html:errors
    Changing ActionErrors to ActionMessages in struts application
    Error Message Not Displaying on JSP(URGENT)