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.kuali.ole.fp.document.web.struts.VoucherForm;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.document.datadictionary.AccountingLineViewFieldDefinition;
27 import org.kuali.ole.sys.document.service.AccountingLineRenderingService;
28 import org.kuali.ole.sys.document.web.renderers.FieldRenderer;
29 import org.kuali.rice.kns.web.ui.Field;
30 import org.kuali.rice.krad.util.ObjectUtils;
31
32
33
34
35
36 public class AccountingLineViewDebitCreditAmountField implements RenderableElement, ElementNamable {
37 private Field debitOrCreditField;
38 private AccountingLineViewFieldDefinition definition;
39 private boolean isDebit;
40 private String newLineProperty;
41 private String collectionProperty;
42 private int arbitrarilyHighIndex;
43
44
45
46
47
48
49
50
51
52 public AccountingLineViewDebitCreditAmountField(Field debitOrCreditField, AccountingLineViewFieldDefinition definition, boolean isDebit, String newLineProperty, String collectionProperty) {
53 this.debitOrCreditField = debitOrCreditField;
54 this.definition = definition;
55 this.isDebit = isDebit;
56 this.newLineProperty = newLineProperty;
57 this.collectionProperty = collectionProperty;
58 }
59
60
61
62
63
64
65 public void appendFields(List<Field> fields) {
66 fields.add(debitOrCreditField);
67 }
68
69
70
71
72
73 public boolean isActionBlock() {
74 return false;
75 }
76
77
78
79
80
81 public boolean isEmpty() {
82 return false;
83 }
84
85
86
87
88
89 public boolean isHidden() {
90 return false;
91 }
92
93
94
95
96 public void populateWithTabIndexIfRequested(int reallyHighIndex) {
97 this.arbitrarilyHighIndex = reallyHighIndex;
98 }
99
100
101
102
103 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
104 if (!renderingContext.isFieldModifyable(debitOrCreditField.getPropertyName())) {
105 debitOrCreditField.setReadOnly(true);
106 }
107 FieldRenderer renderer = SpringContext.getBean(AccountingLineRenderingService.class).getFieldRendererForField(getDebitOrCreditField(), renderingContext.getAccountingLine());
108 if (renderer != null) {
109 prepareFieldForRendering(getDebitOrCreditField(), (VoucherForm)renderingContext.getForm(), renderingContext.getCurrentLineCount());
110 renderer.setField(getDebitOrCreditField());
111 renderer.render(pageContext, parentTag);
112 renderer.clear();
113 }
114 }
115
116
117
118
119
120
121
122
123
124 protected void prepareFieldForRendering(Field field, VoucherForm form, Integer count) {
125 getDebitOrCreditField().setPropertyPrefix(null);
126
127
128 if (count == null) {
129 field.setPropertyName(getNewLineProperty());
130 } else {
131 final String subPropertyName = isDebit ? "debit" : "credit";
132 field.setPropertyName(getCollectionProperty()+"["+count.toString()+"]."+subPropertyName);
133 }
134
135
136 field.setPropertyValue(ObjectUtils.getPropertyValue(form, field.getPropertyName()));
137 }
138
139
140
141
142
143 public int getArbitrarilyHighIndex() {
144 return arbitrarilyHighIndex;
145 }
146
147
148
149
150
151 public String getCollectionProperty() {
152 return collectionProperty;
153 }
154
155
156
157
158
159 public Field getDebitOrCreditField() {
160 return debitOrCreditField;
161 }
162
163
164
165
166
167 public AccountingLineViewFieldDefinition getDefinition() {
168 return definition;
169 }
170
171
172
173
174
175 public boolean isDebit() {
176 return isDebit;
177 }
178
179
180
181
182
183 public String getNewLineProperty() {
184 return newLineProperty;
185 }
186
187
188
189
190 public String getName() {
191 return this.getDebitOrCreditField().getPropertyName();
192 }
193
194 }