2013-04-22 69 views
0

A有一個新特性,它迫使我將一些新的數據結構傳遞給我的EJB。EJB - 將上下文數據從JSF傳遞到EJB

這是一個用戶會話上下文,其中包含有關當前用戶的一些信息。

如何在不重構我的方法簽名和調用的情況下將此數據傳遞給我的EJB?

使用ThreadLocal?但是,如果它不在同一個JVM上?

下面有一些代碼。你能給我一個小費嗎?

/** created at login time, when user put it's credential */ 
public class UserSessionContext { 
    private User current; 
    private Company company; 
    // getters e setters 
} 

/** web page controller */ 
@ManagedBean // at web tier 
public class ListCustomersController { 

    @EJB 
    CustomersRepository customers; // some remote interface 

    // getters/setters 
    private List<Filters> filters; // from the UI 

    /** used in a datatable component */ 
    public List<Customer> getAll(){ 
     return customers.getAllWith(filters); // I have no UserSessionContext parameter 
    } 

} 

/** used by web controller */ 
@Stateless 
public CustomersEJB implements CustomersRepository { 

    @Inject 
    UserSessionContext currentContext; // injected before call this object 

    public List<Customer> getAllWith(List<Filter> filters){ 

     TypeQuery<Customer> customersQuery = ... // 
     customersQuery.setParameter("company",currentContext.getCompany()); 

     return customersQuery.getResultList(); 

    } 

} 

回答

0

有沒有這樣做的標準機制(JSR-149)。 WebSphere Application Server有一個Work Area Service編程模型擴展,可用於以這種方式傳播上下文。