01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License version 2
11: * as published by the Free Software Foundation.
12: *
13: * Resin Open Source is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16: * of NON-INFRINGEMENT. See the GNU General Public License for more
17: * details.
18: *
19: * You should have received a copy of the GNU General Public License
20: * along with Resin Open Source; if not, write to the
21: *
22: * Free Software Foundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Scott Ferguson
27: */
28:
29: package javax.faces.event;
30:
31: import javax.el.*;
32: import javax.faces.application.*;
33: import javax.faces.component.*;
34: import javax.faces.context.*;
35:
36: public class MethodExpressionActionListener implements ActionListener,
37: StateHolder {
38: private MethodExpression _expr;
39: private boolean _isTransient;
40:
41: public MethodExpressionActionListener() {
42: }
43:
44: public MethodExpressionActionListener(MethodExpression expr) {
45: _expr = expr;
46: }
47:
48: public boolean isTransient() {
49: return _isTransient;
50: }
51:
52: public void setTransient(boolean isTransient) {
53: _isTransient = isTransient;
54: }
55:
56: public void processAction(ActionEvent actionEvent) {
57: FacesContext context = FacesContext.getCurrentInstance();
58:
59: _expr.invoke(context.getELContext(),
60: new Object[] { actionEvent });
61: }
62:
63: public Object saveState(FacesContext context) {
64: if (_expr != null)
65: return _expr.getExpressionString();
66: else
67: return null;
68: }
69:
70: public void restoreState(FacesContext context, Object state) {
71: if (state != null) {
72: String expr = (String) state;
73:
74: Application app = context.getApplication();
75: ExpressionFactory factory = app.getExpressionFactory();
76:
77: _expr = factory.createMethodExpression(context
78: .getELContext(), expr, void.class,
79: new Class[] { ActionEvent.class });
80: }
81: }
82: }
|