コード例 #1
0
  @Override
  protected ActionForward handleSubmit(final ActionContext context) throws Exception {
    final EditCustomFieldPossibleValueForm form = context.getForm();
    final Collection<CustomFieldPossibleValue> resolveAllValues = resolveAllValues(context);
    Boolean isInsert = null;
    CustomField field = null;
    CustomFieldPossibleValue parentValue = null;
    Nature nature = getNature(form);
    final BaseCustomFieldService<CustomField> service = resolveService(nature);
    try {
      for (final CustomFieldPossibleValue possibleValue : resolveAllValues) {
        if (isInsert == null) {
          isInsert = possibleValue.getId() == null;
          field = service.load(possibleValue.getField().getId());
          parentValue = possibleValue.getParent();
        }
        service.save(possibleValue);
      }
      context.sendMessage(
          isInsert ? "customField.possibleValue.inserted" : "customField.possibleValue.modified");

      final Map<String, Object> params = new HashMap<String, Object>();
      params.put("nature", nature);
      params.put("fieldId", field.getId());

      switch (field.getNature()) {
        case MEMBER_RECORD:
          final MemberRecordCustomField memberRecordField = (MemberRecordCustomField) field;
          final Long memberRecordTypeId = memberRecordField.getMemberRecordType().getId();
          params.put("memberRecordTypeId", memberRecordTypeId);
          break;
        case PAYMENT:
          final PaymentCustomField paymentField = (PaymentCustomField) field;
          final TransferType transferType = paymentField.getTransferType();
          params.put("transferTypeId", transferType.getId());
          params.put("accountTypeId", transferType.getFrom().getId());
          break;
      }

      if (parentValue != null) {
        params.put("parentValueId", parentValue.getId());
      }
      return ActionHelper.redirectWithParams(
          context.getRequest(), context.getSuccessForward(), params);
    } catch (final DaoException e) {
      return context.sendError("customField.possibleValue.error.saving");
    }
  }