@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"); } }
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final RemoveCustomFieldPossibleValueForm form = context.getForm(); final long id = form.getPossibleValueId(); if (id <= 0) { throw new ValidationException(); } final Nature nature = getNature(form); final Map<String, Object> params = new HashMap<String, Object>(); String key; try { final BaseCustomFieldService<CustomField> service = resolveService(nature); final CustomFieldPossibleValue possibleValue = service.loadPossibleValue(id); final CustomField customField = possibleValue.getField(); switch (customField.getNature()) { case PAYMENT: final PaymentCustomField paymentField = (PaymentCustomField) customField; params.put("transferTypeId", paymentField.getTransferType().getId()); break; case MEMBER_RECORD: final MemberRecordCustomField memberRecordField = (MemberRecordCustomField) customField; params.put("memberRecordTypeId", memberRecordField.getMemberRecordType().getId()); default: service.removePossibleValue(id); break; } key = "customField.possibleValue.removed"; } catch (final DaoException e) { key = "customField.possibleValue.error.removing"; } params.put("fieldId", form.getFieldId()); params.put("nature", nature); context.sendMessage(key); return ActionHelper.redirectWithParams( context.getRequest(), context.getSuccessForward(), params); }