Hi folks,
I have got Controller-ManagedBeans and Model-ManagedBeans (like MVC-Pattern).
Here my Controller:
@ManagedBean
@RequestScoped
public class ProjectController {
private ProjectData projectBean; //The Model-ManagedBean (see below)!
private IProjectService projectService; //My Service-Layer
public ProjectController(){
init();
}
private void init(){
projectBean = new ProjectData();
projectService = new ProjectService();
}
public String saveProject() {
projectService.addProject(projectBean.getProjectDTO());
return ("");
}
}
...and her you can see my model, which gets its values out of a facelet...
@ManagedBean(name="ProjectData")
@SessionScoped
public class ProjectData {
private ProjectDTO projectDTO;
public ProjectData(){
projectDTO = new ProjectDTO();
}
public ProjectDTO getProjectDTO() {
return projectDTO;
}
public void setProjectDTO(ProjectDTO projectDTO) {
this.projectDTO = projectDTO;
}
public String getTitle() {
return projectDTO.getTitle();
}
public void setTitle(String title) {
projectDTO.setTitle(title);
}
}
My problem is now that it doesn't work. I think I need to inject the dependency between those two classes. But how? Is there a JSF-pro that can help me. I would like to use annotations. Thanks
Update after BalusC's post
I changed my code a little bit, but it still doesn't work. Any further advice, please.
@ManagedBean(name="projectData")
@SessionScoped
public class ProjectData {
...
@ManagedProperty(value="#{projectData}")
private ProjectData projectData;
The error com.sun.faces.mgbean.ManagedBeanCreationException
says that the controller bean can not be created because projectData (the model-bean) is not found..