2013-04-22 59 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编程模型扩展,可用于以这种方式传播上下文。