KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > examples > madlib > SelectionActionHandler


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.examples.madlib;
8
9
10 import com.inversoft.error.BasicError;
11 import com.inversoft.error.ErrorRegistry;
12 import com.inversoft.verge.mvc.controller.Action;
13
14
15 /**
16  * <p>
17  * This is an ActionHandler that selects the MadLib the user
18  * has choosen. This finds the MadLib and determines what all
19  * is required for it.
20  * </p>
21  *
22  * @author Brian Pontarelli
23  */

24 public class SelectionActionHandler {
25
26     /**
27      * The success action String return value
28      */

29     public static final String JavaDoc SUCCESS_ACTION = "success";
30
31     /**
32      * The failure action String return value
33      */

34     public static final String JavaDoc FAILURE_ACTION = "failure";
35
36
37     /**
38      * Construsts a new <code>SelectionActionHandler</code>
39      */

40     public SelectionActionHandler() {
41         // Empty
42
}
43
44
45     public Object JavaDoc handleSelect(Action action) {
46         // Retrieve the bean
47
MadLibBean mb = (MadLibBean) action.getHttpSession().getAttribute("madLibBean");
48         
49         // The title should be set, so fetch the Madlib the user selected
50
try {
51             MadLib madLib = MadLibFactory.buildMadLib(mb.getTitle());
52             if (madLib == null) {
53                 BasicError error = ErrorRegistry.getBasicError(MadLibValidator.ERROR_BUNDLE,
54                     "notFound", null, this);
55                 action.getRequestContext().addError(error);
56                 return FAILURE_ACTION;
57             }
58
59             mb.setMadLib(madLib);
60         } catch (MadLibException mle) {
61             BasicError error = ErrorRegistry.getBasicError(MadLibValidator.ERROR_BUNDLE,
62                 "invalid", null, this);
63             action.getRequestContext().addError(error);
64             return FAILURE_ACTION;
65         }
66
67         // Set the bean is session scope and we are starting a new MadLib, we
68
// need to reset it here
69
mb.reset();
70
71         return SUCCESS_ACTION;
72     }
73 }
74
Free Books   Free Magazines  
Popular Tags