1 7 package com.inversoft.verge.examples.madlib; 8 9 import com.inversoft.error.BasicError; 10 import com.inversoft.error.ErrorRegistry; 11 import com.inversoft.verge.mvc.controller.Action; 12 13 14 22 public class CreateActionHandler { 23 24 27 public static final String SUCCESS_ACTION = "success"; 28 29 32 public static final String FAILURE_ACTION = "failure"; 33 34 37 public static final String CANCEL_ACTION = "cancel"; 38 39 40 43 public CreateActionHandler() { 44 } 46 47 48 55 public Object handleCreate(Action action){ 56 57 if (action.getRequestContext().hasErrors()) { 59 return FAILURE_ACTION; 60 } 61 62 MadLibBean mb = (MadLibBean) action.getHttpSession().getAttribute("madLibBean"); 64 65 try { 67 String finalMadLib = MadLibBuilder.buildMadLib(mb); 68 mb.setFinalMadLib(finalMadLib); 69 } catch (MadLibException mle) { 70 BasicError error = ErrorRegistry.getBasicError(MadLibValidator.ERROR_BUNDLE, 71 "creation", null, this); 72 action.getRequestContext().addError(error); 73 return FAILURE_ACTION; 74 } 75 76 return SUCCESS_ACTION; 77 } 78 79 85 public Object handleCancel(Action action) { 86 action.getRequestContext().clear(); 87 return CANCEL_ACTION; 88 } 89 } | Popular Tags |