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.krad.uif.UifConstants.Position;
20 import org.kuali.rice.krad.uif.container.View;
21 import org.kuali.rice.krad.uif.core.Component;
22 import org.kuali.rice.krad.uif.core.ComponentBase;
23 import org.kuali.rice.krad.uif.util.ComponentFactory;
24
25 import java.util.List;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class FieldBase extends ComponentBase implements Field {
43 private static final long serialVersionUID = -5888414844802862760L;
44
45 private String shortLabel;
46
47 private LabelField labelField;
48
49 private String labelPlacement;
50 private boolean labelFieldRendered;
51
52 public FieldBase() {
53 labelFieldRendered = false;
54
55 labelPlacement = Position.LEFT;
56 }
57
58
59
60
61
62
63
64
65
66 @Override
67 public void performInitialization(View view) {
68 super.performInitialization(view);
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 @Override
87 public void performFinalize(View view, Object model, Component parent) {
88 super.performFinalize(view, model, parent);
89
90 if (labelField != null) {
91 labelField.setLabelForComponentId(this.getId());
92
93 if ((getRequired() != null) && getRequired().booleanValue()) {
94 labelField.getRequiredMessageField().setRender(true);
95 }
96 else {
97 setRequired(new Boolean(false));
98 labelField.getRequiredMessageField().setRender(true);
99 String prefixStyle = "";
100 if(StringUtils.isNotBlank(labelField.getRequiredMessageField().getStyle())){
101 prefixStyle = labelField.getRequiredMessageField().getStyle();
102 }
103 labelField.getRequiredMessageField().setStyle(prefixStyle + ";" + "display: none;");
104 }
105
106 if (StringUtils.equals(labelPlacement, Position.RIGHT)) {
107 labelField.setRenderColon(false);
108 }
109 }
110 }
111
112
113
114
115 @Override
116 public final String getComponentTypeName() {
117 return "field";
118 }
119
120
121
122
123 @Override
124 public List<Component> getNestedComponents() {
125 List<Component> components = super.getNestedComponents();
126
127 components.add(labelField);
128
129 return components;
130 }
131
132
133
134
135 public String getLabel() {
136 if (labelField != null) {
137 return labelField.getLabelText();
138 }
139
140 return null;
141 }
142
143
144
145
146 public void setLabel(String label) {
147 if (StringUtils.isNotBlank(label) && labelField == null) {
148 labelField = ComponentFactory.getLabelField();
149 }
150
151 if (labelField != null) {
152 labelField.setLabelText(label);
153 }
154 }
155
156
157
158
159 public String getShortLabel() {
160 return this.shortLabel;
161 }
162
163
164
165
166 public void setShortLabel(String shortLabel) {
167 this.shortLabel = shortLabel;
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181
182 public void setShowLabel(boolean showLabel) {
183 if (labelField != null) {
184 labelField.setRender(showLabel);
185 }
186 }
187
188
189
190
191 public LabelField getLabelField() {
192 return this.labelField;
193 }
194
195
196
197
198 public void setLabelField(LabelField labelField) {
199 this.labelField = labelField;
200 }
201
202 public String getLabelPlacement() {
203 return this.labelPlacement;
204 }
205
206 public void setLabelPlacement(String labelPlacement) {
207 this.labelPlacement = labelPlacement;
208 }
209
210
211
212
213 public boolean isLabelFieldRendered() {
214 return this.labelFieldRendered;
215 }
216
217
218
219
220 public void setLabelFieldRendered(boolean labelFieldRendered) {
221 this.labelFieldRendered = labelFieldRendered;
222 }
223 }