pranxas
Nov 8th, 2006, 07:31 AM
Hi
I'm making an application where I need to have a bean, containing all the user information, which can be accessed in the DB layer(DAO's). The problem is that I don't know how to create and instantiate it, since it will only be build after the user logs on.
I'll try to explain better showing the code:
-The class which I want to make a bean:
public class User_Permissions {
private User user;
private LinkedList<GroupPermOperations> listGpo;
// ...Getters and setters
}
-The controller where I want to create the bean:
public class LoginFormController extends SimpleFormController{
private UserManager userMan;
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,Object command, BindException errors) throws Exception{
String username=((PasswordGetter) command).getUser();
logger.info(((PasswordGetter)command).getUser());
String inputPass=((PasswordGetter) command).getPassword();
String realPass=userMan.getPassword(username);
if(realPass==null){
logger.info("user rejected");
errors.rejectValue("password","error.wrongPassword",null,"Wrong Password");
return new ModelAndView(this.getFormView(), errors.getModel());
}
else if(inputPass.equals(realPass)){
User person=userMan.getInfoList(username);
int user_id=userMan.getUserId(username);
User_Permissions up=userMan.getUserPermissions(user_id);
up.setUser(person);
//HERE IS WHERE I WANT TO MAKE THE BEAN FROM 'up'
WebUtils.setSessionAttribute(request, "activeUser", up);
ModelAndView nModel= new ModelAndView(new RedirectView(getSuccessView()));
return nModel;
}
else{
logger.info("password rejected");
errors.rejectValue("password","error.wrongPassword",null,"Wrong Password");
return new ModelAndView(this.getFormView(), errors.getModel());
}
}
}
How can I also define this bean in the servlet.xml?
Can anybody help me on this?
Thanks is advance
Rui Gonçalves
I'm making an application where I need to have a bean, containing all the user information, which can be accessed in the DB layer(DAO's). The problem is that I don't know how to create and instantiate it, since it will only be build after the user logs on.
I'll try to explain better showing the code:
-The class which I want to make a bean:
public class User_Permissions {
private User user;
private LinkedList<GroupPermOperations> listGpo;
// ...Getters and setters
}
-The controller where I want to create the bean:
public class LoginFormController extends SimpleFormController{
private UserManager userMan;
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,Object command, BindException errors) throws Exception{
String username=((PasswordGetter) command).getUser();
logger.info(((PasswordGetter)command).getUser());
String inputPass=((PasswordGetter) command).getPassword();
String realPass=userMan.getPassword(username);
if(realPass==null){
logger.info("user rejected");
errors.rejectValue("password","error.wrongPassword",null,"Wrong Password");
return new ModelAndView(this.getFormView(), errors.getModel());
}
else if(inputPass.equals(realPass)){
User person=userMan.getInfoList(username);
int user_id=userMan.getUserId(username);
User_Permissions up=userMan.getUserPermissions(user_id);
up.setUser(person);
//HERE IS WHERE I WANT TO MAKE THE BEAN FROM 'up'
WebUtils.setSessionAttribute(request, "activeUser", up);
ModelAndView nModel= new ModelAndView(new RedirectView(getSuccessView()));
return nModel;
}
else{
logger.info("password rejected");
errors.rejectValue("password","error.wrongPassword",null,"Wrong Password");
return new ModelAndView(this.getFormView(), errors.getModel());
}
}
}
How can I also define this bean in the servlet.xml?
Can anybody help me on this?
Thanks is advance
Rui Gonçalves