在applicationContext文件中,我添加了包来映射它。 调用到达,但变量仍为空,不会传递给服务器。在其他类中,同样正常工作。
提前致谢!
@ManagedBean(name="registerUser")
@SessionScoped
public class RegisterUser{
@ManagedProperty("#{userService}")
private DAOUser userService;
private User user = new User();
public DAOUser getUserService() {
return userService;
}
public void setUserService(DAOUser userService) {
this.userService = userService;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String register() {
// Calling Business Service
String passwordEncripada = PasswordControl.encriptString(user.getPassword());
user.setPassword(passwordEncripada);
userService.register(user);
// Add message
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("Registro realizado"));
return "";
}
和DAOUser类:
@Component
public class DAOUser implements Serializable {
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
@Transactional
public void register(User user){
// Acquire session
Session session = sessionFactory.getCurrentSession();
// Save employee, saving behavior get done in a transactional manner
session.save(user);
}
}
编辑:调用setter,但它发送的对象为null
答案 0 :(得分:0)
我认为问题在于DAOUser类名称的规范化。我已经使用@Repository(" userService")而不是@Component,它已经在使用了。
@Repository("userService")
public class DAOUser implements Serializable {
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
@Transactional
public void register(User user){
// Acquire session
Session session = sessionFactory.getCurrentSession();
// Save employee, saving behavior get done in a transactional manner
session.save(user);
}
}