View Javadoc

1   /*
2    * $Id: TestAction.java 817333 2009-09-21 17:29:44Z wesw $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2;
23  
24  import java.util.*;
25  
26  import org.apache.struts2.views.jsp.ui.User;
27  
28  import com.opensymphony.xwork2.Action;
29  import com.opensymphony.xwork2.ActionSupport;
30  import com.opensymphony.xwork2.util.ValueStack;
31  
32  
33  /***
34   */
35  public class TestAction extends ActionSupport {
36  
37      private static final long serialVersionUID = -8891365561914451494L;
38  
39      private Collection collection;
40      private Collection collection2;
41      private Map map;
42      private String foo;
43      private Integer fooInt;
44      private String result;
45      private User user;
46      private String[] array;
47      private String[][] list;
48      private List list2;
49      private List list3;
50      private SomeEnum status = SomeEnum.COMPLETED;
51  
52      private final Map<String, String> texts = new HashMap<String, String>();
53  
54      /***
55       * Define a text resource within this action that will be returned by the getText methods
56       * here before delegating to the default TextProvider
57       *
58       * call
59       * @param key
60       * @param value
61       */
62      public void setText(String key, String value) {
63          this.texts.put(key, value);
64      }
65  
66      /*** Returns the test value if defined otherwise delegates to the default TextProvider */
67      public String getText(String key) {
68          if (this.texts.containsKey(key)) {
69              return this.texts.get(key);
70          }
71          return super.getText(key);
72      }
73  
74      /*** This is the method invoked by the {@link org.apache.struts2.util.TextProviderHelper}.
75       * Returns the test value if defined otherwise delegates to the default TextProvider */
76      public String getText(String key, String defaultValue, List args, ValueStack stack) {
77          if (this.texts.containsKey(key)) {
78              return this.texts.get(key);
79          } else {
80              return super.getText(key, defaultValue, args, stack);
81          }
82      }
83  
84      public Collection getCollection() {
85          return collection;
86      }
87  
88      public void setCollection(Collection collection) {
89          this.collection = collection;
90      }
91  
92      public Map getMap() {
93          return map;
94      }
95  
96      public void setMap(Map map) {
97          this.map = map;
98      }
99  
100     public String getFoo() {
101         return foo;
102     }
103 
104     public void setFoo(String foo) {
105         this.foo = foo;
106     }
107 
108     public String getResult() {
109         return result;
110     }
111 
112     public void setResult(String result) {
113         this.result = result;
114     }
115 
116     public User getUser() {
117         return user;
118     }
119 
120     public void setUser(User user) {
121         this.user = user;
122     }
123 
124     public String[] getArray() {
125         return array;
126     }
127 
128     public void setArray(String[] array) {
129         this.array = array;
130     }
131 
132     public String[][] getList() {
133         return list;
134     }
135 
136     public void setList(String[][] list) {
137         this.list = list;
138     }
139 
140     public List getList2() {
141         return list2;
142     }
143 
144     public void setList2(List list2) {
145         this.list2 = list2;
146     }
147 
148     public void setList3(List list) {
149         this.list3 = list;
150     }
151 
152     public List getList3() {
153         return this.list3;
154     }
155 
156     public Collection getCollection2() {
157         return this.collection2;
158     }
159 
160     public void setCollection2(Collection collection) {
161         this.collection2 = collection;
162     }
163 
164     public Integer getFooInt() {
165         return fooInt;
166     }
167 
168     public void setFooInt(Integer fooInt) {
169         this.fooInt = fooInt;
170     }
171 
172     public String execute() throws Exception {
173         if (result == null) {
174             result = Action.SUCCESS;
175         }
176 
177         return result;
178     }
179 
180     public String executeThrowsException() throws Exception {
181         throw new StrutsException("something went wrong!");
182     }
183 
184     public String doInput() throws Exception {
185         return INPUT;
186     }
187 
188 	public SomeEnum getStatus() {
189 		return status;
190 	}
191 
192 	public void setStatus(SomeEnum status) {
193 		this.status = status;
194 	}
195     
196     public List<SomeEnum> getStatusList() {
197     	return Arrays.asList(SomeEnum.values());
198     }
199 
200 }