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 * Name of the address book
56 private String addressbookName;
59 * Remote addressbook bean
61 private final AddressbookSessionBeanRemote addressbookBean;
67 private UserLoginWebController loginController;
72 public AddressbookWebBean () {
75 // Get initial context
76 Context context = new InitialContext();
79 this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("ejb/stateless-addressbook"); //NOI18N
80 } catch (final NamingException e) {
82 throw new FaceletException(e);
89 this.addressbookList = new ArrayList<>(0);
91 // Is the user logged-in?
92 if (this.loginController.isLoggedIn()) {
93 // Fill list with entries
94 this.addressbookList = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser());
99 public boolean hasCreatedAddressbooks () {
100 // Is the user logged in?
101 if (!this.loginController.isLoggedIn()) {
103 throw new FaceletException("This method can only be called as logged-in user.");
106 // Check if the list is filled
107 return (!this.addressbookList.isEmpty());
111 public void addAddressbook() {
112 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
116 public String getAddressbookName() {
117 return this.addressbookName;
121 public void setAddressbookName(final String addressbookName) {
122 this.addressbookName = addressbookName;