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.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
22 import org.kuali.rice.krad.datadictionary.validator.Validator;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.element.Link;
25 import org.kuali.rice.krad.uif.util.LifecycleElement;
26 import org.kuali.rice.krad.uif.widget.LightBox;
27
28
29
30
31
32
33 @BeanTag(name = "linkField-bean", parent = "Uif-LinkField")
34 public class LinkField extends FieldBase {
35 private static final long serialVersionUID = -1908504471910271148L;
36
37 private Link link;
38
39 public LinkField() {
40 super();
41 }
42
43
44
45
46
47
48
49
50
51
52 @Override
53 public void performInitialization(Object model) {
54 super.performInitialization(model);
55
56 if (StringUtils.isBlank(getLinkText())) {
57 setLinkText(this.getLabel());
58 }
59 }
60
61
62
63
64
65
66
67
68
69 @Override
70 public void performFinalize(Object model, LifecycleElement parent) {
71 super.performFinalize(model, parent);
72
73
74 if (this.getFieldLabel() != null && this.getLink() != null && StringUtils.isNotBlank(this.getLink().getId())) {
75 this.getFieldLabel().setLabelForComponentId(this.getLink().getId());
76 }
77 }
78
79
80
81
82
83
84 @BeanTagAttribute(name="link",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
85 public Link getLink() {
86 return link;
87 }
88
89
90
91
92
93
94 public void setLink(Link link) {
95 this.link = link;
96 }
97
98
99
100
101
102
103 @BeanTagAttribute(name="linkText")
104 public String getLinkText() {
105 return link.getLinkText();
106 }
107
108
109
110
111
112
113 public void setLinkText(String linkLabel) {
114 link.setLinkText(linkLabel);
115 }
116
117
118
119
120
121
122 @BeanTagAttribute(name="target")
123 public String getTarget() {
124 return link.getTarget();
125 }
126
127
128
129
130
131
132 public void setTarget(String target) {
133 link.setTarget(target);
134 }
135
136
137
138
139
140
141 @BeanTagAttribute(name="href")
142 public String getHref() {
143 return link.getHref();
144 }
145
146
147
148
149
150
151 public void setHref(String hrefText) {
152 link.setHref(hrefText);
153 }
154
155
156
157
158
159
160 public void setLightBox(LightBox lightBox) {
161 if (link != null) {
162 link.setLightBox(lightBox);
163 }
164 }
165
166
167
168
169
170
171 @BeanTagAttribute(name="lightBox",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
172 public LightBox getLightBox() {
173 if (link != null) {
174 return link.getLightBox();
175 }
176
177 return null;
178 }
179
180
181
182
183 @Override
184 public void completeValidation(ValidationTrace tracer){
185 tracer.addBean(this);
186
187
188 if(getLink()==null){
189 if(Validator.checkExpressions(this, "link")){
190 String currentValues [] = {"link = "+getLink()};
191 tracer.createError("Link should be set",currentValues);
192 }
193 }
194
195
196 if(getLabel()==null){
197 if(Validator.checkExpressions(this, "label")){
198 String currentValues [] = {"label ="+getLabel(),"link ="+getLink()};
199 tracer.createWarning("Label is null, link should be used instead",currentValues);
200 }
201 }
202
203 super.completeValidation(tracer.getCopy());
204 }
205 }