1 package org.kuali.rice.krad.uif.container.extension;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.rice.core.api.util.type.TypeUtils;
5 import org.kuali.rice.krad.uif.UifConstants;
6 import org.kuali.rice.krad.uif.field.DataFieldBase;
7
8 import java.util.List;
9
10
11
12
13
14
15
16
17
18
19
20 public class ListDataField extends DataFieldBase {
21
22
23 private static final String DL = "DL";
24
25 private boolean applyCssOnItem = false;
26
27 public boolean isApplyCssOnItem() {
28 return applyCssOnItem;
29 }
30
31 public void setApplyCssOnItem(boolean applyCssOnItem) {
32 this.applyCssOnItem = applyCssOnItem;
33 }
34
35
36
37
38
39
40
41
42 @Override
43 protected String generateReadOnlyListDisplayReplacement(List<?> list) {
44 StringBuilder generatedHtml = new StringBuilder();
45
46
47 if (getReadOnlyListDisplayType() == null) {
48 this.setReadOnlyListDisplayType(UifConstants.ReadOnlyListTypes.DELIMITED.name());
49 }
50
51
52 if (getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.UL.name())) {
53 generatedHtml.append("<ul class='uif-readOnlyStringList ").append(getStyleClassesAsString()).append("'>");
54 } else if (getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.OL.name())) {
55 generatedHtml.append("<ol class='uif-readOnlyStringList ").append(getStyleClassesAsString()).append("'>");
56 } else if (getReadOnlyListDisplayType().equalsIgnoreCase(DL)) {
57 generatedHtml.append("<dl class='uif-readOnlyStringList ").append(getStyleClassesAsString()).append("'>");
58 } else if (getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.BREAK.name())) {
59 setReadOnlyListDelimiter("<br/>");
60 } else if (this.getReadOnlyListDelimiter() == null) {
61 setReadOnlyListDelimiter(", ");
62 }
63
64
65 for (Object value : list) {
66
67 if (!TypeUtils.isSimpleType(value.getClass()) || StringUtils.isBlank(value.toString())) {
68 continue;
69 }
70
71
72 if (isApplyMask()) {
73 value = getMaskFormatter().maskValue(value);
74 }
75
76
77
78
79
80
81 if (getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.UL.name())
82 || getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.OL.name())) {
83 generatedHtml.append("<li");
84 if(applyCssOnItem) generatedHtml.append(" '").append(value.toString()).append("'");
85 generatedHtml.append(">").append(value.toString()).append("</li>");
86 } else if (getReadOnlyListDisplayType().equalsIgnoreCase(DL)) {
87 generatedHtml.append("<dd");
88 if(applyCssOnItem) generatedHtml.append(" '").append(value.toString()).append("'");
89 generatedHtml.append(">").append(value.toString()).append("</dd>");
90 } else {
91
92 generatedHtml.append(value.toString()).append(this.getReadOnlyListDelimiter());
93 }
94 }
95
96
97 if (getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.UL.name())) {
98 generatedHtml.append("</ul>");
99 } else if (getReadOnlyListDisplayType().equalsIgnoreCase(UifConstants.ReadOnlyListTypes.OL.name())) {
100 generatedHtml.append("</ol>");
101 } else if (getReadOnlyListDisplayType().equalsIgnoreCase(DL)) {
102 generatedHtml.append("</dl>");
103 }else {
104 generatedHtml.delete(generatedHtml.length() - this.getReadOnlyListDelimiter().length(), generatedHtml.length() );
105 }
106
107 if (generatedHtml.length() > 0) {
108 this.setReadOnlyDisplayReplacement(generatedHtml.toString());
109 } else {
110
111 this.setReadOnlyDisplayReplacement(" ");
112 }
113 return getReadOnlyDisplayReplacement();
114 }
115 }