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 java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24 import org.kuali.rice.krad.datadictionary.validator.Validator;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26 import org.kuali.rice.krad.uif.UifConstants;
27 import org.kuali.rice.krad.uif.component.Component;
28 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
29 import org.kuali.rice.krad.uif.util.ComponentFactory;
30 import org.kuali.rice.krad.uif.util.LifecycleElement;
31 import org.kuali.rice.krad.util.KRADConstants;
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 String requiredIndicator;
52 private boolean renderRequiredIndicator;
53
54 private Message richLabelMessage;
55 private List<Component> inlineComponents;
56
57 public Label() {
58 renderColon = true;
59 }
60
61
62
63
64
65
66 @Override
67 public void performApplyModel(Object model, LifecycleElement parent) {
68 super.performApplyModel(model, parent);
69
70 if (richLabelMessage == null && labelText != null &&
71 labelText.contains(KRADConstants.MessageParsing.LEFT_TOKEN) &&
72 labelText.contains(KRADConstants.MessageParsing.RIGHT_TOKEN)) {
73 Message message = ComponentFactory.getMessage();
74 message.setMessageText(labelText);
75 message.setInlineComponents(inlineComponents);
76 message.setRenderWrapperTag(false);
77
78 this.setRichLabelMessage(message);
79 }
80
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95 @Override
96 public void performFinalize(Object model, LifecycleElement parent) {
97 super.performFinalize(model, parent);
98
99 if (StringUtils.isBlank(getLabelText())) {
100 setRender(false);
101 }
102
103 String defaultRequiredIndicator = (String) KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryBean(
104 UifConstants.REQUIRED_INDICATOR_ID);
105
106 if (requiredIndicator != null && !requiredIndicator.equals(defaultRequiredIndicator)) {
107 this.addDataAttribute(UifConstants.DataAttributes.REQ_INDICATOR, requiredIndicator);
108 } else if (requiredIndicator == null) {
109 requiredIndicator = defaultRequiredIndicator;
110 }
111
112 if ((getRequired() != null) && getRequired().booleanValue()) {
113 setRenderRequiredIndicator(true);
114 }
115 }
116
117
118
119
120
121
122
123
124
125
126
127 @BeanTagAttribute(name="labelForComponentId")
128 public String getLabelForComponentId() {
129 return this.labelForComponentId;
130 }
131
132
133
134
135
136
137 public void setLabelForComponentId(String labelForComponentId) {
138 this.labelForComponentId = labelForComponentId;
139 }
140
141
142
143
144
145
146 @BeanTagAttribute(name="labelText")
147 public String getLabelText() {
148 return this.labelText;
149 }
150
151
152
153
154
155
156 public void setLabelText(String labelText) {
157 this.labelText = labelText;
158 }
159
160
161
162
163
164
165
166
167 @BeanTagAttribute(name="renderColon")
168 public boolean isRenderColon() {
169 return this.renderColon;
170 }
171
172
173
174
175
176
177 public void setRenderColon(boolean renderColon) {
178 this.renderColon = renderColon;
179 }
180
181
182
183
184
185
186
187
188
189 public boolean isRenderRequiredIndicator() {
190 return renderRequiredIndicator;
191 }
192
193
194
195
196
197
198 public void setRenderRequiredIndicator(boolean renderRequiredIndicator) {
199 this.renderRequiredIndicator = renderRequiredIndicator;
200 }
201
202
203
204
205
206
207
208
209
210
211
212
213 @BeanTagAttribute(name="requiredIndicator")
214 public String getRequiredIndicator() {
215 return requiredIndicator;
216 }
217
218
219
220
221
222
223 public void setRequiredIndicator(String requiredIndicator) {
224 this.requiredIndicator = requiredIndicator;
225 }
226
227
228
229
230
231
232
233
234 @BeanTagAttribute(name="richLabelMessage",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
235 public Message getRichLabelMessage() {
236 return richLabelMessage;
237 }
238
239
240
241
242
243
244
245
246 public void setRichLabelMessage(Message richLabelMessage) {
247 this.richLabelMessage = richLabelMessage;
248 }
249
250
251
252
253
254
255 @ViewLifecycleRestriction
256 @BeanTagAttribute(name="inlineComponents",type= BeanTagAttribute.AttributeType.LISTBEAN)
257 public List<Component> getInlineComponents() {
258 return inlineComponents;
259 }
260
261
262
263
264
265
266 public void setInlineComponents(List<Component> inlineComponents) {
267 this.inlineComponents = inlineComponents;
268 }
269
270
271
272
273 @Override
274 public void completeValidation(ValidationTrace tracer){
275 tracer.addBean(this);
276
277 if(tracer.getValidationStage()== ValidationTrace.BUILD){
278
279 if(isRender() && getLabelText()==null){
280 if(!Validator.checkExpressions(this, "labelText")) {
281 String currentValues [] = {"render = "+isRender(),"labelText ="+getLabelText()};
282 tracer.createError("LabelText should be set if render is true",currentValues);
283 }
284 }
285 }
286
287 super.completeValidation(tracer.getCopy());
288 }
289 }