Announcement Announcement Module
Collapse
No announcement yet.
@Service injected into @Managed Bean return null in @Postconstruct Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Service injected into @Managed Bean return null in @Postconstruct

    Hi,

    I have few methods to be called in init() of managedbean.

    My ManagedBean is
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package project.web.jsf;
    
    import java.util.ArrayList;
    import java.util.List;
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import project.bo.ProjectBo;
    import project.domain.Project;
    
    
    /**
     *
     * @author Surineni
     */
    @ManagedBean
    public class ProjectsSummary {
        @ManagedProperty(name = "projectBo", value = "#{projectBo}")
        private ProjectBo projectBo;
        private List<Project> porjectList;
        private Project selectedProject;
    
        
         @PostConstruct
        public void init(){
            porjectList = new ArrayList<Project>();
        
            porjectList = projectBo.loadAllProjects();
        }
        /**
         * @return the porjectList
         */
        public List<Project> getPorjectList() {
            return porjectList;
        }
    
        /**
         * @param porjectList the porjectList to set
         */
        public void setPorjectList(List<Project> porjectList) {
            this.porjectList = porjectList;
        }
    
        /**
         * @return the selectedProject
         */
        public Project getSelectedProject() {
            return selectedProject;
        }
    
        /**
         * @param selectedProject the selectedProject to set
         */
        public void setSelectedProject(Project selectedProject) {
            this.selectedProject = selectedProject;
        }
    
        /**
         * @return the projectBo
         */
        public ProjectBo getProjectBo() {
            return projectBo;
        }
    
        /**
         * @param projectBo the projectBo to set
         */
        public void setProjectBo(ProjectBo projectBo) {
            this.projectBo = projectBo;
        }
        
        
          
    }

    My ProjectBoImpl.java is

    Code:
    @Service("projectBo")
    public class ProjectBoImpl implements ProjectBo {
    
        @Autowired
        private ProjectDao projectDao;
    
        //getters and setters
        public void setProjectDao(ProjectDao projectDao) {
            this.projectDao = projectDao;
        }
    
        public ProjectDao getProjectDao() {
            return projectDao;
        }
    
        
    
        @Override
        public List<Project> loadAllProjects() {
            System.out.println("ProjectBoImpl Entering findAllProjects in BO");
            return getProjectDao().findAllProjects();
        }
    
    }
    My PostConstruct is throwing a nullpointerexception. But it works fine when I call the the same projectBo.loadAllProjects() from getprojectList(). It also works fine when get the ProjectBo from webcontext in @PostConstruct.

    Please advice if I am missing anything

    Thanks
    Vinaya
Working...
X