1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
public class LookupAction extends LookupDispatchAction {
private static Logger theLogger = Logger.getLogger(LookupAction.class.getName());
PhoneBook aPhoneBook = PhoneBook.getInstance();
public static final String OPERATION_AJOUTER = "operation.ajouter";
public static final String OPERATION_MODIFIER = "operation.modifier";
public static final String OPERATION_SUPPRIMER = "operation.supprimer";
public static final String OPERATION_TRIER = "operation.sort";
public Map getKeyMethodMap() {
Map<String, String> map = new HashMap<String, String>();
map.put(OPERATION_AJOUTER, "ajouter");
map.put(OPERATION_MODIFIER, "modifier");
map.put(OPERATION_SUPPRIMER, "supprimer");
map.put(OPERATION_TRIER, "trier");
return map;
}
public ActionForward ajouter(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, RecordException {
ActionErrors errors = new ActionErrors();
LookupForm lookupForm = (LookupForm) form;
String lastname = lookupForm.getLastname();
String firstname = lookupForm.getFirstname();
String phone = lookupForm.getPhone();
String departement = lookupForm.getDepartement();
Employee employee = new Employee(new Personne(firstname, lastname),
phone, departement);
HashMap<String, Employee> map = new HashMap<String, Employee>();
if (request.getSession().getAttribute("map") != null) {
map = (HashMap<String, Employee>) request.getSession()
.getAttribute("map");
}
try{
aPhoneBook.addRecord(employee, employee.getPhone());
map = (HashMap<String, Employee>) aPhoneBook.getPhonebooklist();
}catch(PhoneBookException e){
errors.add("errorsaddreccord", new ActionMessage("errors.addrecord.keyfound"));
}
request.getSession().setAttribute("map", map);
lookupForm.doResetAddForm(mapping, request);
this.saveErrors(request, errors);
return (mapping.findForward("page"));
}
} |
Partager