View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.tag.composite;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.context.FacesContext;
23  import javax.faces.event.AbortProcessingException;
24  import javax.faces.event.ActionEvent;
25  import javax.faces.event.ActionListener;
26  import javax.faces.event.ValueChangeEvent;
27  import javax.faces.validator.ValidatorException;
28  
29  public class MockAttributeBean
30  {
31      private String value = "value1";
32  
33      public String getStyle()
34      {
35          return "style1";
36      }
37      
38      public String getStyleClass()
39      {
40          return "styleclass1";
41      }
42      
43      public String getJavaProperty()
44      {
45          return "javaproperty1";
46      }
47      
48      public String doSomethingFunny(String a)
49      {
50          return "somethingFunny"+a;
51      }
52      
53      public String doSomeAction()
54      {
55          return "someAction";
56      }
57      
58      public String getValue()
59      {
60          return value;
61      }
62      
63      private boolean actionListener1Called = false;
64      
65      public boolean isActionListener1Called()
66      {
67          return actionListener1Called;
68      }
69      
70      public void setActionListener1Called(boolean value)
71      {
72          actionListener1Called = value;
73      }
74      
75      public void doSomeActionListener1()
76      {
77          actionListener1Called = true;
78      }
79  
80      private boolean actionListener2Called = false;
81      
82      public boolean isActionListener2Called()
83      {
84          return actionListener2Called;
85      }
86      
87      public void setActionListener2Called(boolean value)
88      {
89          actionListener2Called = value;
90      }
91  
92      public void doSomeActionListener2(ActionEvent evt)
93      {
94          actionListener2Called = true;
95      }
96      
97      private boolean valueChangeListener1Called = false;
98      
99      public boolean isValueChangeListener1Called()
100     {
101         return valueChangeListener1Called;
102     }
103     
104     public void setValueChangeListener1Called(boolean value)
105     {
106         valueChangeListener1Called = value;
107     }
108     
109     public void doSomeValueChangeListener1() throws AbortProcessingException
110     {
111         valueChangeListener1Called = true;
112     }
113 
114     private boolean valueChangeListener2Called = false;
115     
116     public boolean isValueChangeListener2Called()
117     {
118         return valueChangeListener2Called;
119     }
120     
121     public void setValueChangeListener2Called(boolean value)
122     {
123         valueChangeListener2Called = value;
124     }
125 
126     public void doSomeValueChangeListener2(ValueChangeEvent evt) throws AbortProcessingException
127     {
128         valueChangeListener2Called = true;
129     }
130     
131     private boolean validator1Called = false;
132     
133     public boolean isValidator1Called()
134     {
135         return validator1Called;
136     }
137     
138     public void setValidator1Called(boolean value)
139     {
140         validator1Called = value;
141     }
142     
143     public void doSomeValidator1(FacesContext context, UIComponent component, Object value) throws ValidatorException
144     {
145         validator1Called = true;
146     }
147 
148     private ActionListener submitActionListener;
149     private ActionListener cancelActionListener;
150     
151     private boolean submitActionListenerCalled = false;
152     private boolean cancelActionListenerCalled = false;
153     
154     public ActionListener getSubmitActionListener()
155     {
156         if (submitActionListener == null)
157         {
158             submitActionListener = new ActionListener(){
159     
160                 public void processAction(ActionEvent actionEvent)
161                         throws AbortProcessingException
162                 {
163                     //System.out.println("Submit ActionListener executed");
164                     //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Submit ActionListener executed"));
165                     submitActionListenerCalled = true;
166                 }
167             };
168         }
169         return submitActionListener;
170     }
171     
172     public ActionListener getCancelActionListener()
173     {
174         if (cancelActionListener == null)
175         {
176             cancelActionListener = new ActionListener()
177             {
178                 
179                 public void processAction(ActionEvent actionEvent)
180                         throws AbortProcessingException
181                 {
182                     //System.out.println("Cancel ActionListener executed");
183                     //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Cancel ActionListener executed"));
184                     cancelActionListenerCalled = true;
185                 }
186             };
187         }
188         return cancelActionListener;
189     }
190     
191     public String cancelAction()
192     {
193         return "testActionMethodTypeCancel";
194     }
195     
196     public boolean isSubmitActionListenerCalled()
197     {
198         return submitActionListenerCalled;
199     }
200 
201     public boolean isCancelActionListenerCalled()
202     {
203         return cancelActionListenerCalled;
204     }
205 
206     public void setSubmitActionListenerCalled(boolean submitActionListenerCalled)
207     {
208         this.submitActionListenerCalled = submitActionListenerCalled;
209     }
210 
211     public void setCancelActionListenerCalled(boolean cancelActionListenerCalled)
212     {
213         this.cancelActionListenerCalled = cancelActionListenerCalled;
214     }
215 
216     private String name;
217     
218     public String getName()
219     {
220         return name;
221     }
222 
223     public void setName(String name)
224     {
225         this.name = name;
226     }
227 }