I have worked extensively with seam using POJO components and I am now trying to switch to EJB components.
Imagine this : a page with a list of dogs, and a edit
page to modify the selected dog. When you go back to the list of dog, the list is reloaded. The conversation is long running is only when actually editing a dog.
Can anyone help me : is there a easy way to have a @DataModel list which gets loaded only once, whitout having a long running conversion?
See code below…
The problem with the code below is that even if the « dogs » is outjected in the scope page, the « dogs » will be null at next request because the component will re-init as the conversation is not long running. So the factory will be called again.
It’s also impossible to re-inject the « dogs », because when @DataModel outjects « dogs » in the page scope , it will also « magically » transform the List into a DataModelList….which is ok.
Is there anything wrong with what I try to do? Here’s how I see it…
1. There’s no (good) reason why the list of dog should be in a long running conversation.
2. I just can’t see SQL running twice uselessly without having a panic attack.
@Stateful @Name("dogManager") public class DogManager { @DataModel(scope = ScopeType.PAGE) private List<Dog> dogs; @DataModelSelection @Out(required=false, Scope=ScopeType.CONVERSATION) private Dog dog; @In EntityManager em; @Factory(value = "dogs") public void initDogs() { dogs = (List<Dog>) em.createQuery("SELECT DISTINCT d FROM Dog d ").getResultList(); } @Begin public void edit(){ } @End public void save(){ ... } @End public void cancel(){ ... } ... }