1 package ch.ige.edossier.web.struts;
2
3 import javax.servlet.http.HttpServletRequest;
4 import org.apache.struts.action.*;
5
6
14 public class ContactForm extends ActionForm
15 {
16 private String cbxTo;
17 private String txfNr;
18 private String txfZipCode;
19 private String cbxSection;
20 private String txfEmail;
21 private String txfFirm;
22 private String txfMessage;
23 private String txfName;
24 private String txfCity;
25 private String txfStreet;
26 private String txfPhone;
27
28
32 public String getCbxSection()
33 {
34 return cbxSection;
35 }
36
37 public String getCbxTo()
38 {
39 return cbxTo;
40 }
41
42 public String getTxfCity()
43 {
44 return txfCity;
45 }
46
47 public String getTxfEmail()
48 {
49 return txfEmail;
50 }
51
52 public String getTxfFirm()
53 {
54 return txfFirm;
55 }
56
57 public String getTxfMessage()
58 {
59 return txfMessage;
60 }
61
62 public String getTxfName()
63 {
64 return txfName;
65 }
66
67 public String getTxfNr()
68 {
69 return txfNr;
70 }
71
72 public String getTxfPhone()
73 {
74 return txfPhone;
75 }
76
77 public String getTxfStreet()
78 {
79 return txfStreet;
80 }
81
82 public String getTxfZipCode()
83 {
84 return txfZipCode;
85 }
86
87 public void setTxfZipCode( String txfZipCode )
88 {
89 this.txfZipCode = txfZipCode;
90 }
91
92 public void setTxfStreet( String txfStreet )
93 {
94 this.txfStreet = txfStreet;
95 }
96
97 public void setTxfPhone( String txfPhone )
98 {
99 this.txfPhone = txfPhone;
100 }
101
102 public void setTxfNr( String txfNr )
103 {
104 this.txfNr = txfNr;
105 }
106
107 public void setTxfName( String txfName )
108 {
109 this.txfName = txfName;
110 }
111
112 public void setTxfMessage( String txfMessage )
113 {
114 this.txfMessage = txfMessage;
115 }
116
117 public void setTxfFirm( String txfFirm )
118 {
119 this.txfFirm = txfFirm;
120 }
121
122 public void setTxfEmail( String txfEmail )
123 {
124 this.txfEmail = txfEmail;
125 }
126
127 public void setTxfCity( String txfCity )
128 {
129 this.txfCity = txfCity;
130 }
131
132 public void setCbxTo( String cbxTo )
133 {
134 this.cbxTo = cbxTo;
135 }
136
137 public void setCbxSection( String cbxSection )
138 {
139 this.cbxSection = cbxSection;
140 }
141
142
149 public ActionErrors validate( ActionMapping actionMapping, HttpServletRequest httpServletRequest )
150 {
151 ActionErrors errors = new ActionErrors();
152
153 if( txfName == null || txfName.equals( "" ) )
154 {
155 errors.add( "txfName", new ActionError( "validate.contact.nameRequired" ) );
156 }
157 else if( txfPhone.length() > 40 )
158 {
159 errors.add( "txfName", new ActionError( "validate.contact.nameLength" ) );
160 }
161 if( txfStreet == null || txfStreet.equals( "" ) )
162 {
163 errors.add( "txfStreet", new ActionError( "validate.contact.streetRequired" ) );
164 }
165 if( txfNr == null || txfNr.equals( "" ) )
166 {
167 errors.add( "txfNr", new ActionError( "validate.contact.nrRequired" ) );
168 }
169 if( txfZipCode == null || txfZipCode.equals( "" ) )
170 {
171 errors.add( "txfZipCode", new ActionError( "validate.contact.zipcodeRequired" ) );
172 }
173 else if( txfZipCode.length() > 5 )
174 {
175 errors.add( "txfZipCode", new ActionError( "validate.contact.zipcodeLength" ) );
176 }
177 if( txfCity == null || txfCity.equals( "" ) )
178 {
179 errors.add( "txfCity", new ActionError( "validate.contact.cityRequired" ) );
180 }
181 if( txfPhone.length() > 13 )
182 {
183 errors.add( "txfPhone", new ActionError( "validate.contact.phoneLength" ) );
184 }
185 if( txfEmail == null || txfEmail.equals( "" ) )
186 {
187 errors.add( "txfEmail", new ActionError( "validate.contact.emailRequired" ) );
188 }
189 else if( txfEmail.length() > 50 )
190 {
191 errors.add( "txfEmail", new ActionError( "validate.contact.emailLength" ) );
192 }
193 else if( txfEmail.indexOf( "@" ) == -1 )
194 {
195 errors.add( "txfEmail", new ActionError( "validate.contact.emailNotValid" ) );
196 }
197 return errors;
198 }
199
200
205 public void reset( ActionMapping actionMapping, HttpServletRequest httpServletRequest )
206 {
207 this.cbxTo = null;
208 this.txfNr = "";
209 this.txfZipCode = "";
210 this.cbxSection = null;
211 this.txfEmail = "";
212 this.txfFirm = "";
213 this.txfMessage = "";
214 this.txfName = "";
215 this.txfCity = "";
216 this.txfStreet = "";
217 this.txfPhone = "";
218 }
219 }
220