KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > applications > faces > address > FormElementContainer


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33 package com.icesoft.applications.faces.address;
34
35 import javax.faces.model.SelectItem;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Iterator JavaDoc;
38
39 /**
40  * FormElementContainer references the FormElement objects. It maintains an
41  * ArrayList of all of the elements to use for iteration in the FormProcessor.
42  *
43  * @see AddressFormProcessor
44  */

45 public class FormElementContainer {
46
47     //form text elements
48
private FormElement title, firstName, lastName;
49     private LinkedFormElement city, state, zip;
50
51
52     //submit button
53
private SubmitButton submit;
54
55     private ArrayList JavaDoc titles, componentList;
56
57
58     /**
59      * Instantiates the FormElements and adds them to an ArrayList.
60      */

61     public FormElementContainer() {
62
63         titles = new ArrayList JavaDoc();
64         titles.add("");
65         titles.add("Ms.");
66         titles.add("Mrs.");
67         titles.add("Mr.");
68         titles.add("Dr.");
69
70         //instantiate the form elements
71
title = new FormElement();
72         firstName = new FormElement();
73         lastName = new FormElement();
74         city = new LinkedFormElement();
75         state = new LinkedFormElement();
76         zip = new LinkedFormElement();
77         submit = new SubmitButton();
78
79         /* add the form elements to an array to make iteration
80         possible for reset() and submit.status() */

81         componentList = new ArrayList JavaDoc();
82         componentList.add(title);
83         componentList.add(firstName);
84         componentList.add(lastName);
85         componentList.add(city);
86         componentList.add(state);
87         componentList.add(zip);
88     }
89
90
91     /**
92      * Resets the FormElement's to their original state.
93      */

94     public void reset() {
95
96         //diable submit button
97
submit.setStatus(false);
98
99         Iterator JavaDoc i = componentList.iterator();
100         FormElement current;
101
102         //loop through array of form elements and reset each one
103
while (i.hasNext()) {
104
105             current = (FormElement) i.next();
106             current.reset();
107         }
108     }
109
110     /**
111      * List of titles (Mr., Ms., Dr., etc.).
112      *
113      * @return the the list of titles
114      */

115     public ArrayList JavaDoc getTitles() {
116         return getListAsSelectItems(titles);
117     }
118
119
120     /**
121      * Returns an ArrayList of SelectItem's suitable for a drop-down selection
122      * component.
123      *
124      * @param list The list of choices
125      * @return selectItems The list of SelectItem choices
126      */

127     public ArrayList JavaDoc getListAsSelectItems(ArrayList JavaDoc list) {
128
129         //empty list
130
if (list == null) {
131             return new ArrayList JavaDoc();
132         }
133         //non-empty
134
ArrayList JavaDoc selectItems = new ArrayList JavaDoc(list.size());
135         String JavaDoc val;
136
137         //each entry must be added appropriately for drop-down use
138
for (int index = 0; index < list.size(); index++) {
139             val = (String JavaDoc) list.get(index);
140             selectItems.add(new SelectItem(val, val, ""));
141         }
142         return selectItems;
143     }
144
145     /*
146     * Form element object getters and setters.
147     * The actual Strings containing the values are stored
148     * internally in each object.
149     */

150
151     public FormElement getTitle() {
152         return title;
153     }
154
155     public void setTitle(FormElement title) {
156         this.title = title;
157     }
158
159     public FormElement getFirstName() {
160         return firstName;
161     }
162
163     public void setFirstName(FormElement firstName) {
164         this.firstName = firstName;
165     }
166
167     public FormElement getLastName() {
168         return lastName;
169     }
170
171     public void setLastName(FormElement lastName) {
172         this.lastName = lastName;
173     }
174
175     public LinkedFormElement getCity() {
176         return city;
177     }
178
179     public void setCity(LinkedFormElement city) {
180         this.city = city;
181     }
182
183     public LinkedFormElement getState() {
184         return state;
185     }
186
187     public void setState(LinkedFormElement state) {
188         this.state = state;
189     }
190
191     public LinkedFormElement getZip() {
192         return zip;
193     }
194
195     public void setZip(LinkedFormElement zip) {
196         this.zip = zip;
197     }
198
199     public SubmitButton getSubmit() {
200         return submit;
201     }
202
203     public void setSubmit(SubmitButton submit) {
204         this.submit = submit;
205     }
206
207     /**
208      * Get the list of form elements to use for iteration.
209      *
210      * @return the list of form element objects
211      */

212     public ArrayList JavaDoc getComponentList() {
213         return componentList;
214     }
215
216     /**
217      * Set the new list of form elements. Contains submit, first name, last
218      * name, city, state, and zip objects.
219      *
220      * @param componentList the list of form element objects
221      */

222     public void setComponentList(ArrayList JavaDoc componentList) {
223         this.componentList = componentList;
224     }
225 }
Popular Tags