Witam dopiero uczę się javyEE.
W swoim testowym projekcie używam
- JavaServer Faces
- Hibernate 3.2.5
z pobraniem listy nie mam problemu
w klasie PostController
public List<Post> getList()
{
EntityManager em = DBManager.getManager().createEntityManager();
List list = em.createNamedQuery("Post.findAll").getResultList();
em.close();
return list;
}
w html
<ui:repeat value="#{postController.list}" var="post">
...
jednak nie weim czy podejście dla wyciągania 1 elementu jest poprawne:
w klasie PostController
public String getOne()
{
this.post.setId(2);
EntityManager em = DBManager.getManager().createEntityManager();
this.post = em.find(Post.class, post.getId());
em.close();
return "";
}
w html
#{postController.one} // tu wywołuje metody które mi pobierze dane
<h1>#{postController.post.id}</h1><br/>
#{postController.post.name}<br/>
#{postController.post.description}<br/>
Chodzi o to #{postController.one} jakoś to mało eleganckie ..
Dobrze to robię?