[jboss-user] [JBoss Seam] - Re: Abstract components, EL and auto-instantiation
petemuir
do-not-reply at jboss.com
Sun Nov 12 07:21:01 EST 2006
I would suggest using a manager component:
@Name("currentUser")
| @Scope(SESSION)
| @Stateful
| public class CurrentUserManagerBean implements CurrentUserManager {
|
| private User currentUser;
|
| @Create
| public void create() {
| // Initialise the user e.g. get username from JAAS, load user from Persistence Context
| currentUser = ...;
| }
|
| @Unwrap
| public User unwrap() {
| return currentUser;
| }
|
| }
Alternatively you could make the manager stateful and do all the work in @Unwrap,
@Name("currentUser")
| @Stateless
| public class CurrentUserManagerBean implements CurrentUserManager {
|
| @Unwrap
| public User unwrap() {
| // Initialise the user e.g. get username from JAAS, load user from Persistence Context
| User currentUser = em.find(User.class, username);
| return currentUser;
| }
|
| }
or implement a @Factory manager pattern.
@Name("currentUserManager")
| @Stateless
| public class CurrentUserManagerBean implements CurrentUserManager {
|
| @Factory("currentUser")
| public User unwrap() {
| // Initialise the user e.g. get username from JAAS, load user from Persistence Context
| User currentUser = em.find(User.class, username);
| return currentUser;
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3985192#3985192
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3985192
More information about the jboss-user
mailing list