0

frienddet是否可以在内部检索会话getStatusList()或者我应该在构造函数中检索它并将其分配给一个变量。当我在调试模式下运行eclipse时,我发现getStatusList()在遇到以下代码行时多次调用该函数:

<a4j:repeat var="p" value="#{friendBean2.statusList}"
                        iterationStatusVar="loop">

在第五次它给了我错误:

Error reading 'statusList' on type com.bean.FriendBean2

当我找到问题的根源时,结果发现frienddet会话中丢失了。这就是让我发疯的原因

1) 朋友豆2

public List<Status> getStatusList() {
        EntityManager em;
        EntityManagerFactory emf = Persistence
                .createEntityManagerFactory("FreeBird");
        em = emf.createEntityManager();

        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
        User user = (User) session.getAttribute("frienddet");
        Query query = em.createQuery("SELECT s FROM Status s WHERE s.email='"
                + user.getEmail() + "' ORDER BY s.timeMillis desc",
                Status.class);

           // other codes

}
4

0 回答 0