Hi sixseasons,
Thanks for your reply. This is my controller code -
Code:
public class AddressController extends SimpleFormController {
private StateDao stateDao;
private AddressManager addressManager;
private static final String ADDR_ID = "id";
public AddressController(StateDao stateDao,
AddressManager addressManager) {
this.stateDao = stateDao;
this.addressManager = addressManager;
}
protected Object formBackingObject(HttpServletRequest request) throws Exception {
CustomerAddress command = null;
command = new CustomerAddressImpl();
command.clearValues(); // I found this way from the forum.
return command;
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
BindException errors) throws Exception {
CustomerAddress custAddr = (CustomerAddress) command;
custAddr.setUserId(1);
Address addr = addressManager.getAddress(1);
addressManager.addAddress(custAddr, addr);
Map model = errors.getModel();
model.put("addresses", getAllAddresses());
model.put("states", getStatesRefData());
CustomerAddress newAddr = new CustomerAddressImpl();
model.put(this.getCommandName(), newAddr);
return new ModelAndView(this.getSuccessView(), model);
}
private List getStatesRefData() {
return stateDao.readStatesByCountry("US");
}
private List getAllAddresses() {
return addressManager.getAllAddresses(1);
}
}
In a forum I found a way for doing the same, but it's not working. They have adviced to make a clearValues() method in command object and call it in formBackingObject () method.
Thanks