Struts Error Handling

Reviews
Shared by: Shrikant W
Stats
views:
615
rating:
not rated
reviews:
0
posted:
1/15/2009
language:
English
pages:
0
School voor Communicatie- en Informatiesystemen Directie Vorming Departement Informatiesystemen Kwartier Majoor Housiau Martelarenstraat, 181 1800 PEUTIE Intranet Defensie: http://ecis.mil.intra INFORMATIC PROGRAMMING Enterprise Application Development Designing Front-End Struts Error Handling EAD02 SU05 Struts Error Handling 1. Introduction 2. The ActionError Class 1. ActionError constructors 3. The ActionErrors Class 1. Creating an ActionErrors Instance 2. ActionError Usage 1. Creating ActionError Objects in ActionForms 2. Creating ActionError Objects in Actions 3. Remarks EAD02 SU05 Introduction EAD02 SU05 The ActionError Class Overloaded constructors • • • • API For creating error messages Key resource bundle [ ] values 0–4 Wrapper classes !! ActionError error = new ActionError("error.invalid", new Double(-1)); EAD02 SU05 The ActionErrors Class Creating an ActionErrrors Instance • ActionError stored in ActionErrors • Holds HashMap Key : default ActionErrors.GLOBAL_ERROR Values : ArrayList instances of ActionError instances ActionErrors errors = new ActionErrors(); ActionError error = new ActionError("error.underZero",new Double(-1)); //The error.underZero must be specified in your //resources and use one input parameter errors.add(ActionErrors.GLOBAL_ERROR, error); ... EAD02 SU05 The ActionErrors Class ActionErrror Usage • In ActionForms During validation public ActionErrors validate(ActionMapping mapping, HttpServletRequest req){ ActionErrors errors = new ActionErrors(); // Check and see if the firstName is missing if(firstName == null || firstName.length() == 0) { // Create an error message for the missing firstName value ActionError newError = new ActionError("error.firstname.requiredfield"); errors.add("firstName", newError); } // Check and see if the lastName is missing if(lastName == null || lastName.length() == 0) { // Create an error message for the missing lastName value ActionError newError = new ActionError("error.lastname.requiredfield"); errors.add("lastName", newError); } // Return the ActionErrors, if any. return errors; } EAD02 SU05 The ActionErrors Class ActionErrror Usage • In ActionForms During validation errors.header=Errors :
    errors.footer=

error.lastname.requiredfield=
  • Name is Required
  • error.firstname.requiredfield=
  • FirstName is Required
  • EAD02 SU05 The ActionErrors Class ActionErrror Usage • In Actions class MyAction extends Action { ... public ActionForward execute(..., ...) ActionErrors errors = new ActionErrors(); errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("some.key")); saveErrors(request, errors); return (new ActionForward(mapping.getInput())); } protected void saveErrors(HttpServletRequest request,ActionErrors errors) { // Remove any error messages attribute if none are required if ((errors == null) || errors.empty()) { request.removeAttribute(Action.ERROR_KEY); return; } // Save the error messages we need request.setAttribute(Action.ERROR_KEY, errors); } EAD02 SU05 The ActionErrors Class ActionErrror Usage • In Actions # Error messages global.error.invalidlogin=
  • Invalid Access Number and/or Pin
  • global.error.login.requiredfield=
  • The {0} is required for login
  • else { // If the login method is invalid, throw an InvalidLoginException // Create a msg that can be inserted into a log file String msg = "Invalid Login Attempt by " + accessNumber + ":" + pin; throw new InvalidLoginException( msg ); } EAD02 SU05 The ActionErrors Class Remarks • Extra information messages # Error messages errors.header= …
      errors.footer=
    … errors.prefix= …
  • errors.suffix=
  • … • Use constants EAD02 SU05

    Related docs
    struts
    Views: 117  |  Downloads: 11
    Struts Advanced
    Views: 552  |  Downloads: 67
    struts
    Views: 187  |  Downloads: 11
    Introduction to Struts
    Views: 98  |  Downloads: 16
    Struts with jdev10g
    Views: 273  |  Downloads: 18
    Struts Best Practises
    Views: 114  |  Downloads: 32
    struts
    Views: 1  |  Downloads: 0
    07- Struts- Exceptions
    Views: 2  |  Downloads: 1
    04- Struts- Forms
    Views: 53  |  Downloads: 2
    Struts Exercises
    Views: 297  |  Downloads: 28
    struts
    Views: 52  |  Downloads: 4
    Struts
    Views: 271  |  Downloads: 18
    Struts-and- JSTL
    Views: 57  |  Downloads: 7
    premium docs
    Other docs by Shrikant W
    successstories-scjp
    Views: 131  |  Downloads: 22
    Struts Architecture Diagram
    Views: 911  |  Downloads: 47
    Servlet Session Tracking
    Views: 145  |  Downloads: 18
    Struts with jdev10g
    Views: 273  |  Downloads: 18
    Head-First Design Patterns
    Views: 352  |  Downloads: 97
    Core J2EE Pattern Catalog
    Views: 64  |  Downloads: 5
    Sun-Certi-Presentation
    Views: 230  |  Downloads: 11
    Java SCJP Part1
    Views: 190  |  Downloads: 61
    Java Certification Mock Exam
    Views: 92  |  Downloads: 15
    Java SCJP Certification Help
    Views: 511  |  Downloads: 58
    Java SCJP Certification Education
    Views: 472  |  Downloads: 72
    Struts Advanced
    Views: 552  |  Downloads: 67
    Secret Key Cryptography
    Views: 157  |  Downloads: 14
    DES
    Views: 312  |  Downloads: 11
    Readers Digest Best Jokes
    Views: 370  |  Downloads: 28