1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.exception.RiceRuntimeException;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
23 import org.kuali.rice.krad.uif.UifConstants.Position;
24 import org.kuali.rice.krad.uif.component.ComponentSecurity;
25 import org.kuali.rice.krad.uif.element.Label;
26 import org.kuali.rice.krad.uif.util.MessageStructureUtils;
27 import org.kuali.rice.krad.uif.view.View;
28 import org.kuali.rice.krad.uif.component.Component;
29 import org.kuali.rice.krad.uif.component.ComponentBase;
30 import org.kuali.rice.krad.uif.util.ComponentFactory;
31
32 import java.util.List;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 @BeanTags({@BeanTag(name = "fieldBase-bean", parent = "Uif-FieldBase"),
50 @BeanTag(name = "fieldBase-withLabel-bean", parent = "Uif-FieldBase-withLabel")})
51 public class FieldBase extends ComponentBase implements Field {
52 private static final long serialVersionUID = -5888414844802862760L;
53
54 private String shortLabel;
55 private Label fieldLabel;
56
57 private Position labelPlacement;
58
59 private boolean labelRendered;
60
61 public FieldBase() {
62 labelRendered = false;
63 labelPlacement = Position.LEFT;
64 }
65
66
67
68
69
70
71
72
73
74 @Override
75 public void performInitialization(View view, Object model) {
76 super.performInitialization(view, model);
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 @Override
95 public void performFinalize(View view, Object model, Component parent) {
96 super.performFinalize(view, model, parent);
97
98 if (fieldLabel != null) {
99 fieldLabel.setLabelForComponentId(this.getId());
100
101 if ((getRequired() != null) && getRequired().booleanValue()) {
102 fieldLabel.getRequiredMessage().setRender(!isReadOnly());
103 } else {
104 setRequired(new Boolean(false));
105 fieldLabel.getRequiredMessage().setRender(true);
106
107 String prefixStyle = "";
108 if (StringUtils.isNotBlank(fieldLabel.getRequiredMessage().getStyle())) {
109 prefixStyle = fieldLabel.getRequiredMessage().getStyle();
110 }
111 fieldLabel.getRequiredMessage().setStyle(prefixStyle + ";" + "display: none;");
112 }
113
114 if (labelPlacement.equals(Position.RIGHT)) {
115 fieldLabel.setRenderColon(false);
116 }
117
118 if (labelPlacement.equals(Position.TOP) || labelPlacement.equals(Position.BOTTOM)){
119 fieldLabel.addStyleClass("uif-labelBlock");
120 }
121
122 fieldLabel.addDataAttribute("labelFor", this.getId());
123 if(StringUtils.isNotBlank(this.getFieldLabel().getLabelText())){
124 this.addDataAttribute("label",
125 MessageStructureUtils.translateStringMessage(this.getFieldLabel().getLabelText()));
126 }
127 }
128 }
129
130
131
132
133
134
135
136 protected void setNestedComponentIdAndSuffix(Component component, String suffix) {
137 if (component != null) {
138 String fieldId = getId();
139 fieldId += suffix;
140
141 component.setId(fieldId);
142 }
143 }
144
145
146
147
148 @Override
149 public final String getComponentTypeName() {
150 return "field";
151 }
152
153
154
155
156 @Override
157 public List<Component> getComponentsForLifecycle() {
158 List<Component> components = super.getComponentsForLifecycle();
159
160 components.add(fieldLabel);
161
162 return components;
163 }
164
165
166
167
168 @BeanTagAttribute(name = "label")
169 public String getLabel() {
170 if (fieldLabel != null) {
171 return fieldLabel.getLabelText();
172 }
173
174 return null;
175 }
176
177
178
179
180 public void setLabel(String labelText) {
181 if (StringUtils.isNotBlank(labelText) && this.fieldLabel == null) {
182 this.fieldLabel = ComponentFactory.getLabel();
183 }
184
185 if (this.fieldLabel != null) {
186 this.fieldLabel.setLabelText(labelText);
187 }
188 }
189
190
191
192
193 @BeanTagAttribute(name="labelStyleClasses",type= BeanTagAttribute.AttributeType.LISTVALUE)
194 public List<String> getLabelStyleClasses() {
195 if (fieldLabel != null) {
196 return fieldLabel.getCssClasses();
197 }
198
199 return null;
200 }
201
202
203
204
205 public void setLabelStyleClasses(List<String> labelStyleClasses) {
206 if (labelStyleClasses != null && this.fieldLabel == null) {
207 this.fieldLabel = ComponentFactory.getLabel();
208 }
209
210 if (this.fieldLabel != null) {
211 this.fieldLabel.setCssClasses(labelStyleClasses);
212 }
213 }
214
215
216
217
218 @BeanTagAttribute(name="labelColSpan")
219 public int getLabelColSpan() {
220 if (fieldLabel != null) {
221 return fieldLabel.getColSpan();
222 }
223
224 return 1;
225 }
226
227
228
229
230 public void setLabelColSpan(int labelColSpan) {
231 if (this.fieldLabel == null) {
232 this.fieldLabel = ComponentFactory.getLabel();
233 }
234
235 if (this.fieldLabel != null) {
236 this.fieldLabel.setColSpan(labelColSpan);
237 }
238 }
239
240
241
242
243 @BeanTagAttribute(name="shortLabel")
244 public String getShortLabel() {
245 return this.shortLabel;
246 }
247
248
249
250
251 public void setShortLabel(String shortLabel) {
252 this.shortLabel = shortLabel;
253 }
254
255
256
257
258
259
260
261
262
263
264
265
266 public void setShowLabel(boolean showLabel) {
267 if (fieldLabel != null) {
268 fieldLabel.setRender(showLabel);
269 }
270 }
271
272
273
274
275 @BeanTagAttribute(name="fieldLabel",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
276 public Label getFieldLabel() {
277 return this.fieldLabel;
278 }
279
280
281
282
283 public void setFieldLabel(Label fieldLabel) {
284 this.fieldLabel = fieldLabel;
285 }
286
287
288
289
290
291
292
293 @BeanTagAttribute(name="labelPlacement",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
294 public Position getLabelPlacement() {
295 return this.labelPlacement;
296 }
297
298
299
300
301
302
303 public void setLabelPlacement(Position labelPlacement) {
304 this.labelPlacement = labelPlacement;
305 }
306
307
308
309
310 @BeanTagAttribute(name="labelRendered")
311 public boolean isLabelRendered() {
312 return this.labelRendered;
313 }
314
315
316
317
318 public void setLabelRendered(boolean labelRendered) {
319 this.labelRendered = labelRendered;
320 }
321
322
323
324
325 public FieldSecurity getFieldSecurity() {
326 return (FieldSecurity) super.getComponentSecurity();
327 }
328
329
330
331
332
333
334 @Override
335 public void setComponentSecurity(ComponentSecurity componentSecurity) {
336 if (!(componentSecurity instanceof FieldSecurity)) {
337 throw new RiceRuntimeException("Component security for Field should be instance of FieldSecurity");
338 }
339
340 super.setComponentSecurity(componentSecurity);
341 }
342
343
344
345
346 @Override
347 protected Class<? extends ComponentSecurity> getComponentSecurityClass() {
348 return FieldSecurity.class;
349 }
350 }