-
1. Re: DataModel Page Scope
gonorrhea Jun 12, 2009 8:09 AM (in response to coresystems_rit)You're thinking EVENT scope (refreshed per HTTP request).
-
2. Re: DataModel Page Scope
coresystems_rit Jun 12, 2009 9:32 AM (in response to coresystems_rit)Ok. So EVENT is for each request and page is per page (e.g. for the same page where the data model is used). So if it is used on two pages, for each page it gets rendered?
Unfortunately I can't set an event scope on the data model (only unspecified and page allowed, according to intellij :-)). Can I somehow send an event when the page is reloaded?
I have this requirement because the factory annotated method which loads the data to the data model should get called each time the page gets refreshed.
-
3. Re: DataModel Page Scope
gonorrhea Jun 12, 2009 10:14 AM (in response to coresystems_rit)
The context in which to place the wrapped collection. The only permissible value is ScopeType.PAGE. Default: inherits scope from component or ScopeType.EVENT if component is stateless.SiA book, pg. 236.
The @DataModel annotation exposes an attibute of type java.util.List to the JSF page
as an instance of javax.faces.model.DataModel. This allows us to use the list in a JSF
<h:dataTable> with clickable links for each row. In this case, the DataModel is made
available in a session context variable named messageList.pg. 19, Seam 2.1.2 ref doc
Outjects a property of type List, Map, Set or Object[] as a JSF DataModel into the scope
of the owning component (or the EVENT scope if the owning component is STATELESS).section 31.10.1 Seam ref doc
If @DataModel won't fit your requirement (I don't know what scope your Seam component is), try @Unwrap. This is the Seam manager component pattern.
Here is an example from org.jboss.seam.persistence.ManagedPersistenceContext class:
@Unwrap public EntityManager getEntityManager() throws NamingException, SystemException { if (entityManager==null) initEntityManager(); if ( !synchronizationRegistered && !Lifecycle.isDestroying() ) { joinTransaction(); } return entityManager; }
The @Unwrap annotation tells Seam to provide the return value of the method — the EntityManager
— instead of the actual ManagedPersistenceContext component to clients. This is the Seam manager
component pattern.So basically every time your Seam component is referenced in your JSF, for example, the @Unwrap method will be executed. You can return a javax.faces.model.ListDataModel because that is what is outjected by @DataModel if your context variable is of type java.util.List.
However, this method may be potentially called several times during the rendering of a JSF page, and thus you do not want to have any JPA operations in this method for obvious reasons (unless you check for null first, etc.)...