1
2 package com.pnpconsult.zeiterfassung.actions.admin;
3
4 import java.io.Serializable;
5 import java.util.Collection;
6
7 import javax.servlet.http.HttpServletRequest;
8
9 import org.apache.commons.lang.StringUtils;
10 import org.apache.struts.action.ActionErrors;
11 import org.apache.struts.action.ActionMapping;
12
13 import com.pnpconsult.zeiterfassung.actions.EditForm;
14 import com.pnpconsult.zeiterfassung.model.Customer;
15 import com.pnpconsult.zeiterfassung.util.ActionErrorUtils;
16
17 /***
18 * @author <a href="mailto:powerpete@users.sf.net">M. Petersen</a>
19 * @version $Id: EditCustomerForm.java,v 1.6 2004/06/09 19:26:40 powerpete Exp $
20 *
21 * @struts.form
22 * name="editCustomerForm"
23 */
24 public class EditCustomerForm extends EditForm
25 {
26 private String name;
27 private long id;
28 private Collection projects;
29
30 public ActionErrors validate(
31 ActionMapping mapping,
32 HttpServletRequest request)
33 {
34 ActionErrors errors = new ActionErrors();
35 if (StringUtils.isBlank(name))
36 {
37 ActionErrorUtils.add(errors, "errors.secure.admin.activity.name");
38 }
39 return errors;
40 }
41
42 public void writeToDataObject(Object obj)
43 {
44 Customer customer = (Customer) obj;
45 customer.setName(name);
46 }
47
48 public void readFromDataObject(Object obj)
49 {
50 Customer customer = (Customer) obj;
51 name = customer.getName();
52 projects = customer.getProjects();
53 }
54
55 /***
56 * @return Returns the name.
57 */
58 public String getCustomerName()
59 {
60 return name;
61 }
62
63 /***
64 * @param name The name to set.
65 */
66 public void setCustomerName(String name)
67 {
68 this.name = name;
69 }
70
71 /***
72 * @return Returns the projects.
73 */
74 public Collection getProjects()
75 {
76 return projects;
77 }
78
79 /***
80 * @return Returns the id.
81 */
82 public long getCustomerId()
83 {
84 return id;
85 }
86
87 /***
88 * @param id The id to set.
89 */
90 public void setCustomerId(long id)
91 {
92 this.id = id;
93 }
94
95 /***
96 * @see com.pnpconsult.zeiterfassung.actions.EditForm#newDataObject()
97 */
98 protected Object newDataObject()
99 {
100 return new Customer();
101 }
102
103 /***
104 * @see com.pnpconsult.zeiterfassung.actions.EditForm#dataObjectType()
105 */
106 protected Class dataObjectType()
107 {
108 return Customer.class;
109 }
110
111 /***
112 * @see com.pnpconsult.zeiterfassung.actions.EditForm#dataObjectKey()
113 */
114 protected Serializable dataObjectKey()
115 {
116 return new Long(id);
117 }
118 }