コード例 #1
0
 public ActionForward insertAccount(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   TravelDocumentForm2 travelForm = (TravelDocumentForm2) form;
   TravelAccount travAcct =
       (TravelAccount)
           KNSServiceLocator.getBusinessObjectService().retrieve(travelForm.getTravelAccount());
   // Make sure a travel account was actually retrieved.
   if (travAcct == null) {
     GlobalVariables.getMessageMap()
         .putError(
             "travelAccount.number",
             RiceKeyConstants.ERROR_CUSTOM,
             "Invalid travel account number");
     throw new ValidationException("Invalid travel account number");
   }
   // Insert the travel account into the list, if the list does not already contain it.
   boolean containsNewAcct = false;
   for (Iterator<TravelAccount> travAcctIter =
           ((TravelDocument2) travelForm.getDocument()).getTravelAccounts().iterator();
       travAcctIter.hasNext(); ) {
     if (travAcctIter.next().getNumber().equals(travAcct.getNumber())) {
       containsNewAcct = true;
       break;
     }
   }
   if (!containsNewAcct) {
     ((TravelDocument2) travelForm.getDocument()).getTravelAccounts().add(travAcct);
   }
   travelForm.setTravelAccount(new TravelAccount());
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }
コード例 #2
0
 public ActionForward deleteAccount(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   // Remove the travel account at the index specified in the "methodToCall" parameter.
   TravelDocumentForm2 travelForm = (TravelDocumentForm2) form;
   String strIndex =
       StringUtils.substringBetween(
           (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE),
           KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL,
           KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
   if (StringUtils.isNotBlank(strIndex)) {
     ((TravelDocument2) travelForm.getDocument())
         .getTravelAccounts()
         .remove(Integer.parseInt(strIndex));
   }
   return mapping.findForward(RiceConstants.MAPPING_BASIC);
 }