2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.beans.addressbook;
19 import java.util.ArrayList;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.SessionScoped;
23 import javax.faces.view.facelets.FaceletException;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.addressbook.beans.login.UserLoginWebController;
30 import org.mxchange.addressbook.model.addressbook.Addressbook;
31 import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
34 * A user bean (controller)
36 * @author Roland Haeder<roland@mxchange.org>
38 @Named ("addressbookController")
40 public class AddressbookWebBean implements AddressbookWebController {
45 private static final long serialVersionUID = 185_781_756_712_969L;
47 /////////////////////// Properties /////////////////////
49 * A list of all user's addressbooks
51 private List<Addressbook> addressbookList;
54 * Remote addressbook bean
56 private final AddressbookSessionBeanRemote addressbookBean;
62 private UserLoginWebController loginController;
67 public AddressbookWebBean () {
70 // Get initial context
71 Context context = new InitialContext();
74 this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("ejb/stateless-addressbook"); //NOI18N
75 } catch (final NamingException e) {
77 throw new FaceletException(e);
84 this.addressbookList = new ArrayList<>(0);
86 // Is the user logged-in?
87 if (this.loginController.isLoggedIn()) {
88 // Fill list with entries
89 this.addressbookList = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
94 public boolean hasCreatedAddressbooks () {
95 // Is the user logged in?
96 if (!this.loginController.isLoggedIn()) {
98 throw new FaceletException("This method can only be called as logged-in user.");
101 // Check if the list is filled
102 return (!this.addressbookList.isEmpty());