KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > webapp > bean > UserBean


1 package org.jbpm.webapp.bean;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import javax.faces.model.SelectItem;
8
9 import org.jbpm.identity.User;
10 import org.jbpm.identity.hibernate.IdentitySession;
11 import org.jbpm.security.Authentication;
12 import org.jbpm.webapp.context.Context;
13
14 public class UserBean {
15
16   String JavaDoc userName;
17
18   public String JavaDoc getUserName() {
19     return userName;
20   }
21
22   public void setUserName(String JavaDoc name) {
23     this.userName = name;
24   }
25   
26   public String JavaDoc login() {
27     // user got changed. update the jbpm authentication.
28
Authentication.popAuthenticatedActorId();
29     Authentication.pushAuthenticatedActorId(userName);
30     return "home";
31   }
32
33   public List JavaDoc getUsers() {
34     IdentitySession identitySession = Context.getPersistenceContext().getIdentitySession();
35     return identitySession.getUsers();
36   }
37
38   public List JavaDoc getUserSelectItems() {
39     List JavaDoc userSelectItems = new ArrayList JavaDoc();
40
41     IdentitySession identitySession = Context.getPersistenceContext().getIdentitySession();
42     Iterator JavaDoc iter = identitySession.getUsers().iterator();
43     while (iter.hasNext()) {
44       User user = (User) iter.next();
45       userSelectItems.add(new UserSelectItem(user));
46     }
47     
48     return userSelectItems;
49   }
50   
51   public String JavaDoc getLabel() {
52     return userName;
53   }
54
55   public String JavaDoc getValue() {
56     return userName;
57   }
58   
59   public static class UserSelectItem extends SelectItem {
60     private static final long serialVersionUID = 1L;
61     public UserSelectItem(User user) {
62       setValue(user.getName());
63       setLabel(user.getName());
64     }
65   }
66 }
67
Popular Tags