1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.element;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
22 import org.kuali.rice.krad.datadictionary.validator.Validator;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24 import org.kuali.rice.krad.uif.UifConstants.Position;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.util.ComponentFactory;
27 import org.kuali.rice.krad.uif.view.View;
28 import org.kuali.rice.krad.util.KRADConstants;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37
38
39
40
41
42 @BeanTag(name = "label-bean", parent = "Uif-Label")
43 public class Label extends ContentElementBase {
44 private static final long serialVersionUID = -6491546893195180114L;
45
46 private String labelText;
47 private String labelForComponentId;
48
49 private boolean renderColon;
50
51 private Position requiredMessagePlacement;
52 private Message requiredMessage;
53
54 private Message richLabelMessage;
55 private List<Component> inlineComponents;
56
57 public Label() {
58 renderColon = true;
59
60 requiredMessagePlacement = Position.LEFT;
61 }
62
63
64
65
66
67
68 @Override
69 public void performApplyModel(View view, Object model, Component parent) {
70 super.performApplyModel(view, model, parent);
71
72 if (richLabelMessage == null && labelText != null &&
73 labelText.contains(KRADConstants.MessageParsing.LEFT_TOKEN) &&
74 labelText.contains(KRADConstants.MessageParsing.RIGHT_TOKEN)) {
75 Message message = ComponentFactory.getMessage();
76 view.assignComponentIds(message);
77
78 message.setMessageText(labelText);
79 message.setInlineComponents(inlineComponents);
80 message.setGenerateSpan(false);
81
82 view.getViewHelperService().performComponentInitialization(view, model, message);
83
84 this.setRichLabelMessage(message);
85 }
86 }
87
88
89
90
91
92
93
94
95
96
97 @Override
98 public void performFinalize(View view, Object model, Component parent) {
99 super.performFinalize(view, model, parent);
100
101 if (StringUtils.isBlank(getLabelText())) {
102 setRender(false);
103 }
104 }
105
106
107
108
109 @Override
110 public List<Component> getComponentsForLifecycle() {
111 List<Component> components = super.getComponentsForLifecycle();
112
113 components.add(requiredMessage);
114 components.add(richLabelMessage);
115
116 return components;
117 }
118
119
120
121
122
123
124
125
126
127
128
129 @BeanTagAttribute(name="labelForComponentId")
130 public String getLabelForComponentId() {
131 return this.labelForComponentId;
132 }
133
134
135
136
137
138
139 public void setLabelForComponentId(String labelForComponentId) {
140 this.labelForComponentId = labelForComponentId;
141 }
142
143
144
145
146
147
148 @BeanTagAttribute(name="labelText")
149 public String getLabelText() {
150 return this.labelText;
151 }
152
153
154
155
156
157
158 public void setLabelText(String labelText) {
159 this.labelText = labelText;
160 }
161
162
163
164
165
166
167
168
169 @BeanTagAttribute(name="renderColon")
170 public boolean isRenderColon() {
171 return this.renderColon;
172 }
173
174
175
176
177
178
179 public void setRenderColon(boolean renderColon) {
180 this.renderColon = renderColon;
181 }
182
183
184
185
186
187
188
189
190
191
192
193
194
195 @BeanTagAttribute(name="requiredMessage",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
196 public Message getRequiredMessage() {
197 return this.requiredMessage;
198 }
199
200
201
202
203
204
205 public void setRequiredMessage(Message requiredMessage) {
206 this.requiredMessage = requiredMessage;
207 }
208
209
210
211
212
213
214
215 @BeanTagAttribute(name="requiredMessagePlacement",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
216 public Position getRequiredMessagePlacement() {
217 return this.requiredMessagePlacement;
218 }
219
220
221
222
223
224
225 public void setRequiredMessagePlacement(Position requiredMessagePlacement) {
226 this.requiredMessagePlacement = requiredMessagePlacement;
227 }
228
229
230
231
232
233
234
235
236 @BeanTagAttribute(name="richLabelMessage",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
237 public Message getRichLabelMessage() {
238 return richLabelMessage;
239 }
240
241
242
243
244
245
246
247
248 public void setRichLabelMessage(Message richLabelMessage) {
249 this.richLabelMessage = richLabelMessage;
250 }
251
252
253
254
255
256
257 @BeanTagAttribute(name="inlineComponents",type= BeanTagAttribute.AttributeType.LISTBEAN)
258 public List<Component> getInlineComponents() {
259 return inlineComponents;
260 }
261
262
263
264
265
266
267 public void setInlineComponents(List<Component> inlineComponents) {
268 this.inlineComponents = inlineComponents;
269 }
270
271
272
273
274 @Override
275 public void completeValidation(ValidationTrace tracer){
276 tracer.addBean(this);
277
278 if(tracer.getValidationStage()== ValidationTrace.BUILD){
279
280 if(isRender() && getLabelText()==null){
281 if(!Validator.checkExpressions(this, "labelText")) {
282 String currentValues [] = {"render = "+isRender(),"labelText ="+getLabelText()};
283 tracer.createError("LabelText should be set if render is true",currentValues);
284 }
285 }
286 }
287
288 super.completeValidation(tracer.getCopy());
289 }
290 }