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=

DES
Views: 312 | Downloads: 11