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