import java.util.concurrent.ConcurrentMap;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.LoadedAddressbookEvent;
import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.addressbook.exceptions.AddressbookNotFoundException;
import org.mxchange.addressbook.model.addressbook.Addressbook;
import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
import org.mxchange.addressbook.model.addressbook.UserAddressbook;
@Inject
private UserLoginWebSessionController loginController;
+ /**
+ * Event fired when user has logged in
+ */
+ @Inject
+ @Any
+ private Event<AddressbookLoadedEvent> loadedEvent;
+
/**
* A list of all user's address books
*/
return Objects.equals(this.getAddressbookUser(), this.loginController.getLoggedInUser());
}
+ @Override
+ public boolean loadAddressbook () {
+ // Check if the id is set
+ if (this.getAddressbookId() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.addressbookId is null");
+ } else if (this.getAddressbookId() < 1) {
+ // Not valid id
+ throw new IllegalStateException(MessageFormat.format("this.addressbook={0} is invalid", this.getAddressbookId()));
+ }
+
+ // Default is not found
+ boolean isFound = false;
+
+ try {
+ // Then try to look it up
+ Addressbook a = this.addressbookBean.getAddressbookById(this.getAddressbookId());
+
+ // Fire event here
+ this.loadedEvent.fire(new LoadedAddressbookEvent(a));
+
+ // Found it
+ isFound = true;
+ } catch (final AddressbookNotFoundException ex) {
+ // Not found!
+ throw new FaceletException(ex);
+ }
+
+ // Return status
+ return isFound;
+ }
+
/**
* Initializes the user user's address book list
*/