I have this ManagedBean:
@ManagedBean(name="studentItem")
@ViewScoped
public class StudentBean implements Serializable {
private static final long serialVersionUID = 1L;
@ManagedProperty("#{StudentService}")
private StudentService studentService;
private int regId;
private String firstName;
private String lastName;
//getters and setters
public void saveStudent(StudentBean student) {
//calling from xhtml to save form data
studentService.addStudent(student);
}
}
and this service implementation:
@Component
@Service("StudentService")
public class StudentServiceImpl implements StudentService {
@Autowired
private UserDao<Student> studentDao;
@Override
@Transactional
public void addStudent(StudentBean student) {
Student stu=new Student();
stu.setRegId(student.getRegId());
stu.setFirstName(student.getFirstName());
stu.setLastName(student.getLastName());
studentDao.addItem(stu);
}
}
as you can see, I had to convert my StudentBean
managed-bean object to Student
object type to save it in database using DAO methods. Is there any standard way other than ugly copying properties one by one?