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.ArrayList;
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.ErrorReport;
24 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25 import org.kuali.rice.krad.datadictionary.validator.Validator;
26 import org.kuali.rice.krad.messages.MessageService;
27 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.util.ComponentFactory;
30 import org.kuali.rice.krad.uif.util.LifecycleElement;
31 import org.kuali.rice.krad.uif.widget.LightBox;
32
33
34
35
36
37
38 @BeanTag(name = "link", parent="Uif-Link")
39 public class Link extends ContentElementBase {
40 private static final long serialVersionUID = 8989868231938336068L;
41
42 private String linkText;
43 private String target;
44 private String href;
45
46 private String iconClass;
47 private String linkIconPlacement;
48
49 private String linkDialogId;
50 private boolean openInDialog;
51
52 public Link() {
53 super();
54 linkIconPlacement = UifConstants.Position.LEFT.name();
55 linkDialogId = "";
56 }
57
58
59
60
61
62
63
64
65
66
67 @Override
68 public void performApplyModel(Object model, LifecycleElement parent) {
69 super.performApplyModel(model, parent);
70 }
71
72
73
74
75 @Override
76 public void performFinalize(Object model, LifecycleElement parent) {
77 super.performFinalize(model, parent);
78
79 MessageService messageService = KRADServiceLocatorWeb.getMessageService();
80
81 if (openInDialog){
82 this.addDataAttribute(UifConstants.DataAttributes.ONCLICK, "e.preventDefault(); "
83 + "openLinkInDialog(jQuery(this), \""
84 + linkDialogId + "\");");
85 this.addDataAttribute(UifConstants.DataAttributes.ROLE, UifConstants.RoleTypes.ACTION);
86 }
87
88
89 if (StringUtils.isNotBlank(iconClass) && (UifConstants.ICON_ONLY_PLACEMENT.equals(linkIconPlacement)
90 || StringUtils.isBlank(linkText))) {
91 getCssClasses().add(iconClass);
92
93
94 linkIconPlacement = UifConstants.ICON_ONLY_PLACEMENT;
95 }
96
97 if (target.equals(UifConstants.HtmlAttributeValues.TARGET_BLANK)) {
98 String title = this.getTitle();
99 if (StringUtils.isNotBlank(title)) {
100 this.setTitle(title + " - " + messageService.getMessageText("accessibility.link.opensTab"));
101 }
102 else{
103 this.setTitle(messageService.getMessageText("accessibility.link.opensTab"));
104 }
105 }
106 }
107
108
109
110
111
112
113 @BeanTagAttribute
114 public String getLinkText() {
115 return linkText;
116 }
117
118
119
120
121
122
123 public void setLinkText(String linkText) {
124 this.linkText = linkText;
125 }
126
127
128
129
130
131
132 @BeanTagAttribute
133 public String getTarget() {
134 return target;
135 }
136
137
138
139
140
141
142 public void setTarget(String target) {
143 this.target = target;
144 }
145
146
147
148
149
150
151 @BeanTagAttribute
152 public String getHref() {
153 return href;
154 }
155
156
157
158
159
160
161 public void setHref(String href) {
162 this.href = href;
163 }
164
165
166
167
168
169
170
171
172
173 @BeanTagAttribute
174 public String getLinkDialogId() {
175 return linkDialogId;
176 }
177
178
179
180
181 public void setLinkDialogId(String linkDialogId) {
182 this.linkDialogId = linkDialogId;
183 }
184
185
186
187
188
189
190
191
192
193
194 @BeanTagAttribute
195 public boolean isOpenInDialog() {
196 return openInDialog;
197 }
198
199
200
201
202 public void setOpenInDialog(boolean openInDialog) {
203 this.openInDialog = openInDialog;
204 }
205
206
207
208
209
210
211
212
213
214
215 @BeanTagAttribute
216 public String getIconClass() {
217 return iconClass;
218 }
219
220
221
222
223
224
225 public void setIconClass(String iconClass) {
226 this.iconClass = iconClass;
227 }
228
229
230
231
232
233
234
235
236 @BeanTagAttribute
237 public String getLinkIconPlacement() {
238 return linkIconPlacement;
239 }
240
241
242
243
244
245
246 public void setLinkIconPlacement(String linkIconPlacement) {
247 this.linkIconPlacement = linkIconPlacement;
248 }
249
250
251
252
253 @Override
254 public void completeValidation(ValidationTrace tracer){
255 ArrayList<ErrorReport> reports=new ArrayList<ErrorReport>();
256 tracer.addBean(this);
257
258 if(tracer.getValidationStage()== ValidationTrace.BUILD){
259
260
261 if(getHref()==null){
262 if(!Validator.checkExpressions(this, "href")){
263 String currentValues [] = {"href ="+getHref()};
264 tracer.createError("Href must be set",currentValues);
265 }
266 }
267
268
269 if(getLinkText()==null){
270 if(!Validator.checkExpressions(this, "linkText")){
271 String currentValues [] = {"linkText = "+getLinkText()};
272 tracer.createError("LinkText must be set",currentValues);
273 }
274 }
275
276 }
277
278 super.completeValidation(tracer.getCopy());
279 }
280 }