View Javadoc

1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.myfaces.el;
17  
18  import javax.faces.component.StateHolder;
19  import javax.faces.context.FacesContext;
20  import javax.faces.el.EvaluationException;
21  import javax.faces.el.MethodBinding;
22  import javax.faces.el.MethodNotFoundException;
23  
24  /***
25   * Convenient method binding that does nothing other than returning a fixed outcome String when invoked.
26   *
27   * @author Manfred Geiler
28   */
29  public class SimpleActionMethodBinding
30          extends MethodBinding
31          implements StateHolder
32  {
33      private String _outcome;
34  
35      public SimpleActionMethodBinding(String outcome)
36      {
37          _outcome = outcome;
38      }
39  
40      public Object invoke(FacesContext facescontext, Object aobj[]) throws EvaluationException, MethodNotFoundException
41      {
42          return _outcome;
43      }
44  
45      public Class getType(FacesContext facescontext) throws MethodNotFoundException
46      {
47          return String.class;
48      }
49  
50  
51      //~ StateHolder support ----------------------------------------------------------------------------
52  
53      private boolean _transient = false;
54  
55      /***
56       * Empty constructor, so that new instances can be created when restoring state.
57       */
58      public SimpleActionMethodBinding()
59      {
60          _outcome = null;
61      }
62  
63      public Object saveState(FacesContext facescontext)
64      {
65          return _outcome;
66      }
67  
68      public void restoreState(FacesContext facescontext, Object obj)
69      {
70          _outcome = (String)obj;
71      }
72  
73      public boolean isTransient()
74      {
75          return _transient;
76      }
77  
78      public void setTransient(boolean flag)
79      {
80          _transient = flag;
81      }
82  
83      public String toString()
84      {
85          return _outcome;
86      }
87  }