I am trying to create a base library with controllers and entities that can be extended for several sites and am not sure if I am doing this correctly as I am new to Spring and DI, etc. Any help would be appreciated.
Base Controller
Sub ControllerCode:@Controller public class MyAccountController { public User user; @Inject @Named("User") public void setUser(User user) { this.user = user; } public MyAccountController () {} public MyAccountController (User user) { this.user = user; } public void preProcessSignup(Model model, HttpServletRequest request, HttpSession session, User user) {} @RequestMapping(value = "/processSignup.do", method = { RequestMethod.GET, RequestMethod.POST }) public String doProcessSignup(Model model, HttpServletRequest request, HttpSession session) { user = new User(); preProcessSignup(model, request, session, user); user.setEmail("me@me.com"); user.setUsername("username"); user.setPassword("password"); userDAO.saveUser(user); return "signup"; } }
Base ClassCode:@Controller public class SubMyAccountController extends MyAccountController { public SubMyAccountController() { super(); } public SubMyAccountController(User user) { super(user); } @Inject @Named("User") public void setUser(User user) { this.user = user; } @Override public void preProcessSignup(Model model, HttpServletRequest request, HttpSession session, User user) { user.setRegistrationDate("12/27/2012"); }
Sub ClassCode:@Entity public class User implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) protected String id; protected String username; protected String email; protected String password; //getters and setters, etc. }
Application ContextCode:@Entity public class SubUser extends User { @Id @GeneratedValue(strategy=GenerationType.AUTO) public String id; private String registrationDate; //getters and setters, etc. }
I am using the preProcessSignup method to allow for overriding and setting the extended properties for the subUser object.Code:<bean id="User" class="a.b.c.SubUser" />
However, it is not casting the User object to the subUser and does not recognize the registrationDate property.
What am I doing wrong? Is there a better way to do this? I just want to have base classes / controllers that hold all functionality and data common to these sites. Then extend those classes with pre- and post- methods to implement and differences.
This is probably a basic question, but I am struggling with it.
Thanks for any help or suggestions


Reply With Quote
