import org.mxchange.jusercore.model.user.User;
/**
- * A user bean (controller)
+ * An address book bean (controller)
* <p>
* @author Roland Haeder<roland@mxchange.org>
*/
*/
private AddressbookSessionBeanRemote addressbookBean;
+ /**
+ * When this address book has been created
+ */
+ private Calendar addressbookCreated;
+
/**
* Address book id number (from URL for example)
*/
*/
private String addressbookName;
- /**
- * When this address book has been created
- */
- private Calendar addressbookCreated;
-
/**
* Who owns this address book
*/
}
}
+ @Override
+ public void afterAddressbookLoaded (final @Observes AddressbookLoadedEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null");
+ } else if (event.getAddressbook() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.addressbook is null");
+ } else if (event.getAddressbook().getAddressbookId() == null) {
+ // And again a NPE
+ throw new NullPointerException("event.addressbook.addressbookId is null");
+ } else if (event.getAddressbook().getAddressbookId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException("Address book instance " + event.getAddressbook() + " has invalid id number: " + event.getAddressbook().getAddressbookId());
+ } else if (event.getAddressbook().getAddressbookUser() == null) {
+ // One more NPE ...
+ throw new NullPointerException("event.addressbook.addressbookUser is null");
+ }
+
+ // Get address book instance
+ Addressbook addressbook = event.getAddressbook();
+
+ // Set address book data
+ this.setAddressbookId(addressbook.getAddressbookId());
+ this.setAddressbookName(addressbook.getAddressbookName());
+ this.setAddressbookUser(addressbook.getAddressbookUser());
+ this.setAddressbookCreated(addressbook.getAddressbookCreated());
+ }
+
@Override
public List<Addressbook> allAddressbooks () {
// Is the user logged in?
return Collections.unmodifiableList(this.sharedAddressbooks);
}
+ @Override
+ public Integer countAllUserSharedAddressbooks (final User user) {
+ // Call EJB
+ return this.addressbookBean.countAllUserSharedAddressbooks(user);
+ }
+
@Override
public Calendar getAddressbookCreated () {
return this.addressbookCreated;
// Return status
return isFound;
}
-
- @Override
- public void afterAddressbookLoaded (final @Observes AddressbookLoadedEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null");
- } else if (event.getAddressbook() == null) {
- // Throw NPE again
- throw new NullPointerException("event.addressbook is null");
- } else if (event.getAddressbook().getAddressbookId() == null) {
- // And again a NPE
- throw new NullPointerException("event.addressbook.addressbookId is null");
- } else if (event.getAddressbook().getAddressbookId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException("Address book instance " + event.getAddressbook() + " has invalid id number: " + event.getAddressbook().getAddressbookId());
- } else if (event.getAddressbook().getAddressbookUser() == null) {
- // One more NPE ...
- throw new NullPointerException("event.addressbook.addressbookUser is null");
- }
-
- // Get address book instance
- Addressbook addressbook = event.getAddressbook();
-
- // Set address book data
- this.setAddressbookId(addressbook.getAddressbookId());
- this.setAddressbookName(addressbook.getAddressbookName());
- this.setAddressbookUser(addressbook.getAddressbookUser());
- this.setAddressbookCreated(addressbook.getAddressbookCreated());
- }
}
import org.mxchange.jusercore.model.user.User;
/**
- * An interface for user beans
+ * An interface for address book beans
* <p>
* @author Roland Haeder<roland@mxchange.org>
*/
* <p>
* @param event Event with address book instance
*/
- public void afterAddressbookLoaded (final AddressbookLoadedEvent event);
+ void afterAddressbookLoaded (final AddressbookLoadedEvent event);
+
+ /**
+ * Count all shared address books by given user id
+ * <p>
+ * @param user User instance to look for
+ * <p>
+ * @return Count of user's shared address books
+ */
+ Integer countAllUserSharedAddressbooks (final User user);
}
*/
package org.mxchange.addressbook.beans.login;
-import java.text.MessageFormat;
import java.util.Objects;
import javax.enterprise.context.SessionScoped;
import javax.faces.view.facelets.FaceletException;
@Inject
private UserWebController userController;
+ /**
+ * Flag whether the user has logged-in, set only from inside
+ */
+ private boolean userLoggedIn;
+
/**
* Default constructor
*/
this.templateType = templateType;
}
+ @Override
+ public boolean isGuest () {
+ return (!this.isUserLoggedIn());
+ }
+
@Override
public boolean isUserLoggedIn () {
// Trace message
- System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.loggedInUser={0},this.templateType={1} - CALLED!", this.getLoggedInUser(), this.getTemplateType()));
+ // NOISY: System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.loggedInUser={0},this.templateType={1} - CALLED!", this.getLoggedInUser(), this.getTemplateType()));
// Compare instance
- return ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
+ this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
+
+ // Trace message
+ // NOISY: System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.userLoggedIn={0} - EXIT!", this.userLoggedIn));
+
+ // Return it
+ return this.userLoggedIn;
}
}
* @return Whether the user is logged-in
*/
boolean isUserLoggedIn ();
+
+ /**
+ * Is this truly a guest?
+ * <p>
+ * @return Whether the user is truly a guest
+ */
+ boolean isGuest ();
}
<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition
- rendered="#{loginController.userLoggedIn}"
+ rendered="#{loginController.isUserLoggedIn()}"
template="/WEB-INF/templates/base.tpl"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
</ui:define>
<ui:define name="content">
- <h:outputText rendered="#{shareController.isShareeUserIdSet()}">
+ <ui:fragment rendered="#{shareController.isShareeUserIdSet()}">
Here goes your content.
- </h:outputText>
+ </ui:fragment>
- <h:outputText rendered="#{shareController.isShareeUserIdEmpty()}">
+ <ui:fragment rendered="#{shareController.isShareeUserIdEmpty()}">
<ui:include src="/WEB-INF/templates/generic/userid_error.tpl" />
- </h:outputText>
+ </ui:fragment>
</ui:define>
</ui:composition>
</html>
</div>
<div class="table_footer">
- <h:outputText rendered="#{addressbookController.isOwnAddressbook()}">
+ <ui:fragment rendered="#{addressbookController.isOwnAddressbook()}">
<h:link id="startSharing" outcome="login_start_sharing_addressbook" value="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK}" title="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE}" />
- </h:outputText>
- <h:outputText rendered="#{addressbookController.isOtherAddressbook()}">
+ </ui:fragment>
+
+ <ui:fragment rendered="#{addressbookController.isOtherAddressbook()}">
Bla bla
- </h:outputText>
+ </ui:fragment>
</div>
</div>
</ui:define>
</h:outputFormat>
</h:column>
- <h:outputText rendered="#{loginController.userLoggedIn}">
- <h:column>
- <f:facet name="header">#{msg.USER_LIST_SHARING_ADDRESSBOOKS}</f:facet>
+ <h:column>
+ <f:facet name="header">#{msg.USER_LIST_SHARING_ADDRESSBOOKS}</f:facet>
+ <ui:fragment rendered="#{loginController.isUserLoggedIn()}">
<h:link outcome="login_list_sharing_addressbooks" value="#{msg.LINK_LOGIN_LIST_SHARING_ADDRESSBOOKS}" title="#{msg.LINK_LOGIN_LIST_SHARING_ADDRESSBOOKS_TITLE}">
<f:param name="userId" value="#{user.userId}" />
</h:link>
- </h:column>
- </h:outputText>
+ </ui:fragment>
+ <ui:fragment rendered="#{loginController.isGuest()}">
+ <h:outputText id="userShared" value="#{addressbookController.countAllUserSharedAddressbooks(user)}" />
+ </ui:fragment>
+ </h:column>
</h:dataTable>
</div>
</ui:define>
</ui:define>
<ui:define name="content">
- <h:outputText rendered="#{shareController.isShareeUserIdSet()}">
+ <ui:fragment rendered="#{shareController.isShareeUserIdSet()}">
Here goes your content.
- </h:outputText>
+ </ui:fragment>
- <h:outputText rendered="#{shareController.isShareeUserIdEmpty()}">
+ <ui:fragment rendered="#{shareController.isShareeUserIdEmpty()}">
<ui:include src="/WEB-INF/templates/generic/userid_error.tpl" />
- </h:outputText>
+ </ui:fragment>
</ui:define>
</ui:composition>
</html>