1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.extremecomponents.table.model;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.extremecomponents.table.bean.Form;
24 import org.extremecomponents.table.bean.Input;
25
26
27
28 /***
29 * @author jeff johnston
30 */
31 public class FormHandler
32 {
33 private TableModel model;
34 private Form form;
35 private List inputs = new ArrayList();
36
37 public FormHandler(TableModel model)
38 {
39 this.model = model;
40 }
41
42 public void addForm(Form form)
43 {
44 this.form = form;
45 }
46
47 public Form getForm()
48 {
49 return form;
50 }
51
52 public void addInput(Input input)
53 {
54 inputs.add(input);
55 }
56
57 public String getHiddenFields()
58 {
59 StringBuffer sb = new StringBuffer();
60
61 for (Iterator iter = inputs.iterator(); iter.hasNext();)
62 {
63 Input input = (Input) iter.next();
64 if (input.getType().equals(Input.HIDDEN))
65 {
66 sb.append("\t<input type=\"hidden\" name=\"" + input.getName() + "\" value=\"" + input.getValue() + "\">\n");
67 }
68 }
69
70 return sb.toString();
71 }
72
73 public String getFormButtons()
74 {
75 StringBuffer sb = new StringBuffer();
76
77 for (Iterator iter = inputs.iterator(); iter.hasNext();)
78 {
79 Input input = (Input) iter.next();
80 String type = input.getType();
81 if (type.equals(Input.SUBMIT) || type.equals(Input.BUTTON))
82 {
83 sb.append("<input type=\"" + type + "\" class=\"formButton\" name=\"" + input.getName() + "\" value=\"" + input.getValue() + "\"");
84
85 if (StringUtils.isNotEmpty(input.getOnclick()))
86 {
87 sb.append(" onclick=\"" + input.getOnclick() + "\" ");
88 }
89
90 sb.append(">");
91 }
92 }
93
94 return sb.toString();
95 }
96
97 public void destroy()
98 {
99 inputs.clear();
100 inputs = null;
101 }
102 }