I'm learning SpringMVC 2 and i have a form that i need to bind to an object (the command). But what if i need this command object to be an interface so i can use different implementations for the object (of course all the implementations will have the same fields).
For binding a form that represents an Account i have this controller. Is it possible that i could bind the form to the Account Interface, so i can use it like a business bean after that ?
Or just tell me what are the best spring practices for a flow like: FORM -> do Business Logic -> Save to DB
public class OpenAccountControllerSpring2
extends SimpleFormController {
private ClientDao clientDao;
private Account account;
public OpenAccountControllerSpring2() {
setCommandClass( // dont know what to write here);
setCommandName("newAccount");
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException bindExp)
throws Exception {
try {
//here i just want to create a new Account, add it to a Client (Interface), then transform the Client into a database-bean and save it.
int client_id = Integer.parseInt(request.getParameter("clientId"));
Account account = (Account) command;
Client client = Transformer.toBusinessHeavy(clientDao.getClient(client_id));
client.addAccount(account);
clientDao.updateClient(Transformer.toEntity(client));
} catch (Exception err) {
return new ModelAndView(this.getFormView());
}
return new ModelAndView(this.getSuccessView());
}
public void setClientDao(ClientDao dao) {
this.clientDao = dao;
}
public void setAccount(Account account) {
this.account = account;
}
}