1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.sys.document.web;
20
21 import java.util.List;
22
23 import javax.servlet.jsp.JspException;
24 import javax.servlet.jsp.PageContext;
25 import javax.servlet.jsp.tagext.Tag;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.kfs.sys.KFSConstants;
29 import org.kuali.kfs.sys.businessobject.AccountingLine;
30 import org.kuali.kfs.sys.context.SpringContext;
31 import org.kuali.kfs.sys.document.datadictionary.AccountingLineViewMultipleReadOnlyFieldsDefinition;
32 import org.kuali.kfs.sys.document.web.renderers.MultipleReadOnlyFieldsRenderer;
33 import org.kuali.rice.kns.service.DataDictionaryService;
34 import org.kuali.rice.kns.util.FieldUtils;
35 import org.kuali.rice.kns.web.ui.Field;
36 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
37 import org.kuali.rice.krad.util.ObjectUtils;
38
39
40
41
42 public class AccountingLineViewMultipleReadOnlyFields extends FieldTableJoiningWithHeader {
43 private AccountingLineViewMultipleReadOnlyFieldsDefinition definition;
44 private List<Field> fields;
45 private static DataDictionaryService dataDictionaryService;
46
47
48
49
50
51
52
53
54 public AccountingLineViewMultipleReadOnlyFields(AccountingLineViewMultipleReadOnlyFieldsDefinition definition, List<Field> fields) {
55 this.definition = definition;
56 this.fields = fields;
57 }
58
59
60
61
62
63 public HeaderLabel createHeaderLabel() {
64 return new LiteralHeaderLabel(KFSConstants.BLANK_SPACE);
65 }
66
67
68
69
70
71 public String getName() {
72 return definition.getFieldNames().get(0);
73 }
74
75
76
77
78
79 public void appendFields(List<Field> fields) {}
80
81
82
83
84
85 public void populateWithTabIndexIfRequested(int reallyHighIndex) {}
86
87
88
89
90
91
92 public List<Field> getFields() {
93 return fields;
94 }
95
96
97
98
99
100
101
102 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
103 final org.kuali.rice.krad.datadictionary.BusinessObjectEntry boEntry = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(renderingContext.getAccountingLine().getClass().getName());
104 if (fields != null && !fields.isEmpty()) {
105 for (Field field : fields) {
106 setShortLabelsForFields(field, boEntry);
107 setValueForField(field, renderingContext.getAccountingLine());
108 setInquiryUrlForField(field, renderingContext.getAccountingLine());
109 }
110 }
111
112 MultipleReadOnlyFieldsRenderer renderer = new MultipleReadOnlyFieldsRenderer();
113 renderer.setFields(getFields());
114 renderer.render(pageContext, parentTag);
115 renderer.clear();
116 }
117
118
119
120
121
122
123
124
125 protected void setShortLabelsForFields(Field field, org.kuali.rice.krad.datadictionary.BusinessObjectEntry boEntry) {
126 final AttributeDefinition propertyDefinition = boEntry.getAttributeDefinition(field.getPropertyName());
127 final String label = (propertyDefinition == null) ? "" : (!StringUtils.isBlank(propertyDefinition.getShortLabel()) ? propertyDefinition.getShortLabel() : propertyDefinition.getLabel());
128 field.setFieldLabel(label);
129 }
130
131
132
133
134
135
136
137
138 protected void setValueForField(Field field, AccountingLine accountingLine) {
139 field.setPropertyValue(ObjectUtils.getPropertyValue(accountingLine, field.getPropertyName()));
140 }
141
142
143
144
145
146
147
148
149 protected void setInquiryUrlForField(Field field, AccountingLine accountingLine) {
150 if (!StringUtils.isBlank(field.getPropertyValue())) {
151 FieldUtils.setInquiryURL(field, accountingLine, field.getPropertyName());
152 }
153 }
154
155
156
157
158 protected DataDictionaryService getDataDictionaryService() {
159 if (dataDictionaryService == null) {
160 dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
161 }
162 return dataDictionaryService;
163 }
164
165 }