01: /*
02: * $Id: EditPersonAction.java 476710 2006-11-19 05:05:14Z mrdon $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: package org.apache.struts2.showcase.person;
22:
23: import java.util.ArrayList;
24: import java.util.Iterator;
25: import java.util.List;
26:
27: import org.apache.struts2.config.Result;
28: import org.apache.struts2.config.Results;
29: import org.apache.struts2.dispatcher.ServletRedirectResult;
30:
31: import com.opensymphony.xwork2.ActionSupport;
32:
33: /**
34: * <code>EditPerson</code>
35: *
36: */
37: @Result(name="list",value="listPeople.action",type=ServletRedirectResult.class)
38: public class EditPersonAction extends ActionSupport {
39:
40: private static final long serialVersionUID = 7699491775215130850L;
41:
42: PersonManager personManager;
43: List persons = new ArrayList();
44:
45: public void setPersonManager(PersonManager personManager) {
46: this .personManager = personManager;
47: }
48:
49: public List getPersons() {
50: return persons;
51: }
52:
53: public void setPersons(List persons) {
54: this .persons = persons;
55: }
56:
57: /**
58: * A default implementation that does nothing an returns "success".
59: *
60: * @return {@link #SUCCESS}
61: */
62: public String execute() throws Exception {
63: persons.addAll(personManager.getPeople());
64: return SUCCESS;
65: }
66:
67: /**
68: * A default implementation that does nothing an returns "success".
69: *
70: * @return {@link #SUCCESS}
71: */
72: public String save() throws Exception {
73:
74: // Set people = personManager.getPeople();
75:
76: for (Iterator iter = persons.iterator(); iter.hasNext();) {
77: Person p = (Person) iter.next();
78: personManager.getPeople().remove(p);
79: personManager.getPeople().add(p);
80: }
81: return "list";
82: }
83:
84: }
|