Typically when we retrieve a list of objects, we may want to display it on a web page. Seam provides annotations that allow this to be easily done, without having to create data transfer objects to pass data between the EJB tier and the web tier.
Within our manager Session Bean, we annotate the list of objects with the @DataModel
annotation. Seam will then automatically outject the list as a JSF data model that can be displayed within a Facelets page.
To allow the easy selection of objects within a list, Seam also provides the @DataModelSelection
annotation that is used by Seam to inject an instance of a selected entity in a list. If we apply this to our customerManager
component, we get:
package com.davidsalter.data.actions; import com.davidsalter.data.entity.Customer; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.jboss.seam.annotations.Destroy; import...