2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.view.faces;
19
20 import javax.faces.context.FacesContext;
21 import javax.faces.event.ActionEvent;
22 import javax.faces.event.ActionListener;
23 import org.apache.shale.view.Constants;
24 import org.apache.shale.view.ExceptionHandler;
25
26 /***
27 * <p>Replacement for the default <code>ActionListener</code> implementation
28 * used during the <em>Invoke Application</em> phase of the request processing
29 * lifecycle.</p>
30 *
31 * @since 1.0.3
32 *
33 * $Id: ViewActionListener.java 464373 2006-10-16 04:21:54Z rahul $
34 */
35 public final class ViewActionListener implements ActionListener {
36
37
38
39
40
41 /***
42 * <p>Create a new action listener instance.</p>
43 *
44 * @param original The original action listener instance we are wrapping
45 */
46 public ViewActionListener(ActionListener original) {
47 this.original = original;
48 }
49
50
51
52
53
54 /***
55 * <p>The original <code>ActionListener</code> instance we are wrapping.</p>
56 */
57 private ActionListener original = null;
58
59
60
61
62
63 /***
64 * <p>Handle a default action event.</p>
65 *
66 * @param event The <code>ActionEvent</code> to be handled
67 */
68 public void processAction(ActionEvent event) {
69
70
71
72
73 try {
74 original.processAction(event);
75 } catch (Exception e) {
76 handleException(FacesContext.getCurrentInstance(), e);
77 }
78
79 }
80
81
82
83
84
85 /***
86 * <p>Handle the specified exception according to the strategy
87 * defined by our current {@link ExceptionHandler}.</p>
88 *
89 * @param context FacesContext for the current request
90 * @param exception Exception to be handled
91 */
92 private void handleException(FacesContext context, Exception exception) {
93
94 if (context == null) {
95 exception.printStackTrace(System.out);
96 return;
97 }
98 ExceptionHandler handler = (ExceptionHandler)
99 context.getApplication().getVariableResolver().resolveVariable
100 (context, Constants.EXCEPTION_HANDLER);
101 handler.handleException(exception);
102
103 }
104
105
106 }