On demo site (BLC 2.1.1-SNAPSHOT) when you update an Address, instead of updating the Address row in database a new Address row is created and the CustomerAddress is updated whith the new Address id.
Is it normal ?
On BroadleafManageCustomerAddressesController you have :
Code: Select all
public String updateCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId, CustomerAddressForm form, BindingResult result, RedirectAttributes redirectAttributes) throws ServiceException {
customerAddressValidator.validate(form, result);
if (result.hasErrors()) {
return getCustomerAddressesView();
}
CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId);
if (customerAddress == null) {
throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId");
}
//HERE, you should retrieve the current address id
customerAddress.setAddress(form.getAddress());
customerAddress.setAddressName(form.getAddressName());
customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
if (form.getAddress().isDefault()) {
customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customerAddress.getCustomer().getId());
}
redirectAttributes.addFlashAttribute("successMessage", getAddressUpdatedMessage());
return getCustomerAddressesRedirect();
}
The Address id is always null so a new instance of Address is created.