1
2
3
4
5
6
7
8
9
10
11
12
13
14 package net.sf.tacos.components.dojo.form;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20 import org.apache.tapestry.IMarkupWriter;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.IScript;
23 import org.apache.tapestry.PageRenderSupport;
24 import org.apache.tapestry.TapestryUtils;
25 import org.apache.tapestry.dojo.form.AbstractFormWidget;
26 import org.apache.tapestry.engine.IEngineService;
27 import org.apache.tapestry.form.TranslatedField;
28 import org.apache.tapestry.form.TranslatedFieldSupport;
29 import org.apache.tapestry.form.ValidatableFieldSupport;
30 import org.apache.tapestry.json.JSONObject;
31 import org.apache.tapestry.services.DataSqueezer;
32 import org.apache.tapestry.valid.ValidatorException;
33
34
35
36
37
38
39
40
41
42 public abstract class HtmlArea extends AbstractFormWidget implements TranslatedField
43 {
44
45
46
47
48 protected void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle)
49 {
50 String value = getTranslatedFieldSupport().format(this, getValue());
51
52 renderDelegatePrefix(writer, cycle);
53
54 writer.begin("textarea");
55 writer.attribute("name", getName());
56
57 if (isDisabled())
58 writer.attribute("disabled", "disabled");
59
60 renderIdAttribute(writer, cycle);
61
62 renderDelegateAttributes(writer, cycle);
63
64 getTranslatedFieldSupport().renderContributions(this, writer, cycle);
65 getValidatableFieldSupport().renderContributions(this, writer, cycle);
66
67 renderInformalParameters(writer, cycle);
68
69 if (value != null) writer.print(value);
70
71 writer.end();
72
73 renderDelegateSuffix(writer, cycle);
74
75 Map parms = new HashMap();
76 parms.put("id", getClientId());
77
78 JSONObject json = new JSONObject();
79 json.put((Object)"widgetId", getName());
80 json.put((Object)"name", getName());
81 json.put((Object)"disabled", isDisabled());
82 if (getToolbarTemplatePath()!=null)
83 json.put((Object)"toolbarTemplatePath", getToolbarTemplatePath());
84
85 parms.put("props", json.toString());
86 parms.put("widget", this);
87
88 PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
89 getScript().execute(this, cycle, prs, parms);
90 }
91
92
93
94
95 protected void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle)
96 {
97 String value = cycle.getParameter(getName());
98
99 try
100 {
101 String text = (String) getTranslatedFieldSupport().parse(this, value);
102
103 getValidatableFieldSupport().validate(this, writer, cycle, text);
104
105 setValue(text);
106 }
107 catch (ValidatorException e)
108 {
109 getForm().getDelegate().record(e);
110 }
111 }
112
113 public abstract String getToolbarTemplatePath();
114
115
116 public abstract Object getValue();
117
118
119 public abstract void setValue(Object value);
120
121
122 public abstract DataSqueezer getDataSqueezer();
123
124
125
126
127 public abstract ValidatableFieldSupport getValidatableFieldSupport();
128
129
130
131
132 public abstract TranslatedFieldSupport getTranslatedFieldSupport();
133
134
135
136
137 public abstract IEngineService getDirectService();
138
139
140
141
142 public abstract IScript getScript();
143
144
145
146
147 public boolean isRequired()
148 {
149 return getValidatableFieldSupport().isRequired(this);
150 }
151
152
153
154
155 public List getUpdateComponents()
156 {
157 List comps = new ArrayList();
158 comps.add(getClientId());
159
160 return comps;
161 }
162
163
164
165
166 public boolean isAsync()
167 {
168 return false;
169 }
170
171
172
173
174 public boolean isJson()
175 {
176 return false;
177 }
178 }