01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.financial.web.struts.action;
17:
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.http.HttpServletResponse;
20:
21: import org.apache.struts.action.ActionForm;
22: import org.apache.struts.action.ActionForward;
23: import org.apache.struts.action.ActionMapping;
24: import org.kuali.core.service.DictionaryValidationService;
25: import org.kuali.kfs.KFSConstants;
26: import org.kuali.kfs.KFSPropertyConstants;
27: import org.kuali.kfs.context.SpringContext;
28: import org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase;
29: import org.kuali.module.financial.bo.InternalBillingItem;
30: import org.kuali.module.financial.web.struts.form.InternalBillingForm;
31:
32: /**
33: * This class handles Actions for InternalBilling.
34: */
35: public class InternalBillingAction extends
36: KualiAccountingDocumentActionBase {
37:
38: /**
39: * Adds a new InternalBillingItem from the Form to the Document if valid. This method is called reflectively from KualiAction.
40: *
41: * @param mapping
42: * @param form
43: * @param request
44: * @param response
45: * @return ActionForward
46: * @throws Exception
47: */
48: public ActionForward insertItem(ActionMapping mapping,
49: ActionForm form, HttpServletRequest request,
50: HttpServletResponse response) throws Exception {
51: InternalBillingForm internalBillingForm = (InternalBillingForm) form;
52: if (validateNewItem(internalBillingForm)) {
53: internalBillingForm.getInternalBillingDocument().addItem(
54: internalBillingForm.getNewItem());
55: internalBillingForm.setNewItem(new InternalBillingItem());
56: }
57: return mapping.findForward(KFSConstants.MAPPING_BASIC);
58: }
59:
60: /**
61: * Validates the new InternalBillingItem on the Form, adding a global error if invalid.
62: *
63: * @param internalBillingForm
64: * @return whether the new item is valid
65: */
66: private static boolean validateNewItem(
67: InternalBillingForm internalBillingForm) {
68: return SpringContext.getBean(DictionaryValidationService.class)
69: .isBusinessObjectValid(
70: internalBillingForm.getNewItem(),
71: KFSPropertyConstants.NEW_ITEM);
72: }
73:
74: /**
75: * Deletes an InternalBillingItem from the Document. This method is called reflectively from KualiAction.
76: *
77: * @param mapping
78: * @param form
79: * @param request
80: * @param response
81: * @return ActionForward
82: * @throws Exception
83: */
84: public ActionForward deleteItem(ActionMapping mapping,
85: ActionForm form, HttpServletRequest request,
86: HttpServletResponse response) throws Exception {
87: InternalBillingForm internalBillingForm = (InternalBillingForm) form;
88: internalBillingForm.getInternalBillingDocument().getItems()
89: .remove(getLineToDelete(request));
90: return mapping.findForward(KFSConstants.MAPPING_BASIC);
91: }
92: }
|