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.NamingException;
import org.mxchange.addressbook.beans.login.UserLoginWebSessionController;
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
*/
//this.addressbookBean.getUserCountMap()
}
+ @Override
+ public boolean isAddressbookLoaded () {
+ return ((this.getAddressbookId() instanceof Long)
+ && (this.getAddressbookName() instanceof String)
+ && (!this.getAddressbookName().isEmpty())
+ && (this.getAddressbookUser() instanceof User));
+ }
+
@Override
public boolean isAddressbookNameUsed (final String addressbookName) {
// Is it zero size?
}
@Override
- public boolean isAddressbookLoaded () {
- return ((this.getAddressbookId() instanceof Long)
- && (this.getAddressbookName() instanceof String)
- && (!this.getAddressbookName().isEmpty())
- && (this.getAddressbookUser() instanceof User));
+ 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;
}
/**
* @return Whether the address book is loaded
*/
boolean isAddressbookLoaded ();
+
+ /**
+ * Loads address book from current id
+ *<p>
+ * @return Whether the address book was found
+ */
+ boolean loadAddressbook ();
}
@Inject
private UserLoginWebSessionController loginController;
- /**
- * User instance
- */
- private User user;
-
/**
* User controller
*/
private UserWebSessionController userController;
@Override
- public User getUser () {
- return this.user;
- }
+ public boolean isProfileLinkVisibleById (final Long userId) {
+ // Init user instance
+ User u = null;
- @Override
- public void setUser (final User user) {
- this.user = user;
+ try {
+ // Try to get it
+ u = userController.lookupUserById(userId);
+ } catch (final UserNotFoundException ex) {
+ // Throw again
+ throw new FaceletException(ex);
+ }
+
+ // Is it null?
+ if (null == u) {
+ // Not found, not visible.
+ return false;
+ }
+
+ // Ask other method
+ return this.isProfileLinkVisibleByUser(u);
}
@Override
- public boolean isProfileLinkVisible () {
+ public boolean isProfileLinkVisibleByUser (final User user) {
// Check on user
- if (this.getUser() == null) {
+ if (user == null) {
/*
* Not set, means wrong invocation of this method as the user
* instance needs to be set first.
*/
- throw new NullPointerException("this.user is null"); //NOI18N
- } else if (this.getUser().getUserId() == null) {
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
/*
* If the id number is not set it means that the user instance has
* not been persisted and the JPA has not been flushed. Or a
* "virgin" instance (e.g. from registration) has been used.
*/
- throw new NullPointerException("this.user.userId is null"); //NOI18N
- } else if (this.getUser().getUserId() < 1) {
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
/*
* The id number is set invalid for an unknown reason.
*/
- throw new IllegalArgumentException(MessageFormat.format("this.user.userId={0} is invalid", this.getUser().getUserId())); //NOI18N
- } else if (this.getUser().getUserProfileMode() == null) {
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+ } else if (user.getUserProfileMode() == null) {
/*
* Possibly an out-dated user profile is being used. This should not
* happen.
*/
- throw new NullPointerException("this.user.userProfileMode is null"); //NOI18N
+ throw new NullPointerException("user.userProfileMode is null"); //NOI18N
}
// Get profile mode from user instance (safe now)
- ProfileMode profileMode = this.getUser().getUserProfileMode();
+ ProfileMode profileMode = user.getUserProfileMode();
// Check all conditions (except for admin)
// TODO: Add admin role somehow?
return ((profileMode.equals(ProfileMode.PUBLIC)) ||
(this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS)));
}
-
- @Override
- public boolean isProfileLinkVisibleById (final Long userId) {
- // Init user instance
- User u = null;
-
- try {
- // Try to get it
- u = this.userController.lookupUserById(userId);
- } catch (final UserNotFoundException ex) {
- // Throw again
- throw new FaceletException(ex);
- }
-
- // Set it here
- this.setUser(u);
-
- // Is it null?
- if (null == u) {
- // Not found, not visible.
- return false;
- }
-
- // Ask other method
- return this.isProfileLinkVisible();
- }
-
- @Override
- public boolean isProfileLinkVisibleByUser (final User user) {
- // Is it correctly set?
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null");
- } else if (user.getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userId is null");
- } else if (user.getUserId() < 1) {
- // Invalid user id set
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId()));
- }
-
- // Set user here
- this.setUser(user);
-
- // Ask other method
- return this.isProfileLinkVisible();
- }
}
*/
public interface UserProfileWebRequestController extends Serializable {
- /**
- * Checks if the current user profile link is visible
- * <p>
- * @return Whether the profile link is visible
- */
- boolean isProfileLinkVisible ();
-
/**
* Checks if the user profile link is visible
* <p>
* @return Whether the user's profile is visible
*/
boolean isProfileLinkVisibleByUser (final User user);
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getUser ();
-
- /**
- * Setter for user instance
- * <p>
- * @param user User instance
- */
- void setUser (final User user);
}
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
- <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty profileController.user}" />
+ <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty user}" />
- <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" rendered="#{not empty profileController.user and not profileController.isProfileLinkVisible()}" />
+ <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" rendered="#{not empty user and not profileController.isProfileLinkVisibleByUser(user)}" />
- <h:link id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}" rendered="#{not empty profileController.user and profileController.isProfileLinkVisible()}">
- <h:outputText id="userName" value="#{profileController.user.userName}" />
- <f:param name="userId" value="#{profileController.user.userId}" />
+ <h:link id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}" rendered="#{not empty user and profileController.isProfileLinkVisibleByUser(user)}">
+ <h:outputText id="userName" value="#{user.userName}" />
+ <f:param name="userId" value="#{user.userId}" />
</h:link>
</ui:composition>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
- xmlns:f="http://xmlns.jcp.org/jsf/core"
- xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+ xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="/WEB-INF/templates/login/login_base.tpl">
<ui:define name="login_title">#{msg.PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS}</ui:define>
<div class="para">
<h:dataTable id="sharedAddressbooks" var="share" value="#{shareController.allShares()}" headerClass="table_data_column" summary="#{msg.TABLE_SUMMARY_LOGIN_SHARED_ADDRESSBOOKS}" rendered="#{shareController.isSharingAddressbooks()}">
- <c:set value="#{share.shareUserSharee}" target="#{profileController}" property="user" />
-
<h:column>
<f:facet name="header">#{msg.SHARED_ADDRESSBOOK}</f:facet>
<h:column>
<f:facet name="header">#{msg.SHAREE_USER_NAME}</f:facet>
- <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+ <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+ <ui:param name="user" value="#{share.setShareUserSharee(shareUserSharer)}" />
+ </ui:include>
</h:column>
<h:column>
<h:column>
<f:facet name="header">#{msg.USER_NAME}</f:facet>
- <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+ <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+ <ui:param name="user" value="#{user}" />
+ </ui:include>
</h:column>
<h:column>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
- xmlns:f="http://xmlns.jcp.org/jsf/core"
- xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+ xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewParam id="addressbookId" name="addressbookId" value="#{addressbookController.addressbookId}" required="true" requiredMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_MISSING}" converterMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_INVALID}" validatorMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_NOT_FOUND}">
</ui:define>
<ui:define name="content">
- <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.isAddressbookLoaded()}">
- <c:set value="#{addressbookController.addressbookUser}" target="#{profileController}" property="user" />
-
+ <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.loadAddressbook()}">
<f:facet name="header">#{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}</f:facet>
<h:outputLabel for="addressbookId" class="table_label">#{msg.ADDRESSBOOK_ID}</h:outputLabel>
<h:outputText id="addressbookName" value="#{addressbookController.addressbookName}" />
<h:outputLabel for="userProfileLink" class="table_label">#{msg.ADDRESSBOOK_OWNER}</h:outputLabel>
- <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+ <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+ <ui:param name="user" value="#{addressbookController.addressbookUser}" />
+ </ui:include>
<h:outputLabel for="addressbookCreated" class="table_label">#{msg.ADDRESSBOOK_CREATED}</h:outputLabel>
<h:outputFormat id="addressbookCreated" value="#{addressbookController.addressbook.addressbookCreated.time}" title="#{msg.ADDRESSBOOK_CREATED_TITLE}">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
- xmlns:f="http://xmlns.jcp.org/jsf/core"
- xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+ xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="/WEB-INF/templates/#{loginController.templateType}/#{loginController.templateType}_base.tpl">
<ui:define name="login_title">#{msg.PAGE_TITLE_USER_LIST}</ui:define>
</div>
<h:dataTable id="userList" var="user" value="#{userController.allVisibleUsers()}" headerClass="table_header_column25" summary="#{msg.TABLE_SUMMARY_USER_LIST}" rendered="#{userController.isVisibleUserFound()}">
- <c:set value="#{share.shareUserSharee}" target="#{profileController}" property="user" />
<h:column>
<f:facet name="header">#{msg.USER_ID}</f:facet>
- <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+ <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+ <ui:param name="user" value="#{user}" />
+ </ui:include>
</h:column>
<h:column>
<f:facet name="header">#{msg.USER_NAME}</f:facet>
- <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+ <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+ <ui:param name="user" value="#{user}" />
+ </ui:include>
</h:column>
<h:column>