1
14
15 package com.liferay.taglib.aui;
16
17 import com.liferay.portal.kernel.util.ServerDetector;
18 import com.liferay.portal.kernel.util.Validator;
19 import com.liferay.taglib.util.IncludeTag;
20 import com.liferay.util.PwdGenerator;
21 import com.liferay.util.TextFormatter;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.tagext.DynamicAttributes;
29
30
37 public class InputTag extends IncludeTag implements DynamicAttributes {
38
39 public int doEndTag() throws JspException {
40 try {
41 return super.doEndTag();
42 }
43 catch (Exception e) {
44 throw new JspException(e);
45 }
46 finally {
47 if (!ServerDetector.isResin()) {
48 _bean = null;
49 _changesContext = false;
50 _checked = false;
51 _cssClass = null;
52 _disabled = false;
53 _dynamicAttributes.clear();
54 _field = null;
55 _first = false;
56 _helpMessage = null;
57 _id = null;
58 _inlineField = false;
59 _inlineLabel = null;
60 _label = null;
61 _last = false;
62 _model = null;
63 _name = null;
64 _prefix = null;
65 _suffix = null;
66 _title = null;
67 _type = null;
68 _value = null;
69 }
70 }
71 }
72
73 public int doStartTag() {
74 HttpServletRequest request =
75 (HttpServletRequest)pageContext.getRequest();
76
77 if (_bean == null) {
78 _bean = pageContext.getAttribute("aui:model-context:bean");
79 }
80
81 if (Validator.isNull(_field)) {
82 _field = _name;
83 }
84
85 if (Validator.isNull(_id)) {
86 if (!Validator.equals(_type, "radio")) {
87 _id = _name;
88 }
89 else {
90 _id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
91 }
92 }
93
94 if (_label == null) {
95 _label = TextFormatter.format(_name, TextFormatter.K);
96 }
97
98 if (_model == null) {
99 _model = (Class<?>)pageContext.getAttribute(
100 "aui:model-context:model");
101 }
102
103 request.setAttribute("aui:input:bean", _bean);
104 request.setAttribute(
105 "aui:input:changesContext", String.valueOf(_changesContext));
106 request.setAttribute("aui:input:checked", String.valueOf(_checked));
107 request.setAttribute("aui:input:cssClass", _cssClass);
108 request.setAttribute("aui:input:disabled", String.valueOf(_disabled));
109 request.setAttribute("aui:input:field", _field);
110 request.setAttribute("aui:input:first", String.valueOf(_first));
111 request.setAttribute("aui:input:helpMessage", _helpMessage);
112 request.setAttribute("aui:input:id", _id);
113 request.setAttribute(
114 "aui:input:inlineField", String.valueOf(_inlineField));
115 request.setAttribute("aui:input:inlineLabel", _inlineLabel);
116 request.setAttribute("aui:input:label", _label);
117 request.setAttribute("aui:input:last", String.valueOf(_last));
118 request.setAttribute("aui:input:model", _model);
119 request.setAttribute("aui:input:name", _name);
120 request.setAttribute("aui:input:prefix", _prefix);
121 request.setAttribute("aui:input:suffix", _suffix);
122 request.setAttribute("aui:input:title", _title);
123 request.setAttribute("aui:input:type", _type);
124 request.setAttribute("aui:input:value", _value);
125
126 request.setAttribute("aui:input:dynamicAttributes", _dynamicAttributes);
127
128 return EVAL_BODY_BUFFERED;
129 }
130
131 public void setBean(Object bean) {
132 _bean = bean;
133 }
134
135 public void setChangesContext(boolean changesContext) {
136 _changesContext = changesContext;
137 }
138
139 public void setChecked(boolean checked) {
140 _checked = checked;
141 }
142
143 public void setCssClass(String cssClass) {
144 _cssClass = cssClass;
145 }
146
147 public void setDisabled(boolean disabled) {
148 _disabled = disabled;
149 }
150
151 public void setDynamicAttribute(
152 String uri, String localName, Object value) {
153
154 _dynamicAttributes.put(localName, value);
155 }
156
157 public void setField(String field) {
158 _field = field;
159 }
160
161 public void setFirst(boolean first) {
162 _first = first;
163 }
164
165 public void setHelpMessage(String helpMessage) {
166 _helpMessage = helpMessage;
167 }
168
169 public void setId(String id) {
170 _id = id;
171 }
172
173 public void setInlineField(boolean inlineField) {
174 _inlineField = inlineField;
175 }
176
177 public void setInlineLabel(String inlineLabel) {
178 _inlineLabel = inlineLabel;
179 }
180
181 public void setLabel(String label) {
182 _label = label;
183 }
184
185 public void setLast(boolean last) {
186 _last = last;
187 }
188
189 public void setModel(Class<?> model) {
190 _model = model;
191 }
192
193 public void setName(String name) {
194 _name = name;
195 }
196
197 public void setPrefix(String prefix) {
198 _prefix = prefix;
199 }
200
201 public void setSuffix(String suffix) {
202 _suffix = suffix;
203 }
204
205 public void setTitle(String title) {
206 _title = title;
207 }
208
209 public void setType(String type) {
210 _type = type;
211 }
212
213 public void setValue(Object value) {
214 _value = value;
215 }
216
217 protected String getDefaultPage() {
218 return _PAGE;
219 }
220
221 private static final String _PAGE = "/html/taglib/aui/input/page.jsp";
222
223 private Object _bean;
224 private boolean _changesContext;
225 private boolean _checked;
226 private String _cssClass;
227 private boolean _disabled;
228 private Map<String, Object> _dynamicAttributes =
229 new HashMap<String, Object>();
230 private String _field;
231 private boolean _first;
232 private String _helpMessage;
233 private String _id;
234 private boolean _inlineField;
235 private String _inlineLabel;
236 private String _label;
237 private boolean _last;
238 private Class<?> _model;
239 private String _name;
240 private String _prefix;
241 private String _suffix;
242 private String _title;
243 private String _type;
244 private Object _value;
245
246 }