I'm really confused about the @Inject in Java. I've read about CDI in the Java EE tutorial, and I still don't get it. Would you take a look at my code and tell me what I'm doing wrong?
package model.businessLayer;
import java.util.List;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import model.domainLayer.RADplusUserSupplemental;
@Named(value = "staffLocal")
public class StaffCaseloadMgr implements StaffCaseloadMgrLocal {
@PersistenceContext(unitName = "CareTeamPersist")
EntityManager em;
public StaffCaseloadMgr() {}
/**
* Returns the list of user supplemental records from the database,
* based on the patid passed in to staff caseload.
* @param patid The patient, or consumer ID
* @return List of RADplusUserSupplemental records
*/
public List<RADplusUserSupplemental> getListForEmails(String patid) {
return em.createNamedQuery("StaffCaseload.findEmails",
RADplusUserSupplemental.class)
.getResultList();
}
}
I put the constructor in there, thinking it might help. I'm not sure why it would, though, seeing as how it's the default constructor. Okay, next.
package utils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import model.businessLayer.StaffCaseloadMgr;
import model.domainLayer.RADplusUserSupplemental;
@SessionScoped
public class CareTeam implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
static StaffCaseloadMgr staffLocal;
/**
* This is a static method that retrieves the care team given a particular
* consumer ID.
*
* @param consumerID
* The consumer ID for which to get the care team
*
* @return A list of emails for the care team
*/
public static List<Map<String, String>> getCareTeamEmails(String consumerID) {
List<Map<String, String>> arrayList = new ArrayList<Map<String, String>>();
for (RADplusUserSupplemental userSupp : staffLocal
.getListForEmails(consumerID)) {
Map<String, String> emailMap = new HashMap<String, String>();
emailMap.put("staffEmail", userSupp.getOrganizationEmailAddress());
arrayList.add(emailMap);
}
return arrayList;
}
}
I'm using Maven, so I put an empty beans.xml in resources/META-INF. I'm very confused about why it's not working. Can you help?
Aucun commentaire:
Enregistrer un commentaire