From: Roland Haeder Date: Fri, 16 Oct 2015 17:43:43 +0000 (+0200) Subject: rewrote isProfileLinkVisible() as the previous attempt didn't work X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c87f80285179030fba06f45f7730477fd106b31b;p=jfinancials-war.git rewrote isProfileLinkVisible() as the previous attempt didn't work --- diff --git a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebBean.java b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebBean.java index 520ef170..6adc75d9 100644 --- a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebBean.java @@ -16,6 +16,7 @@ */ package org.mxchange.addressbook.beans.profile; +import java.text.MessageFormat; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; @@ -43,31 +44,25 @@ public class UserProfileWebBean implements UserProfileWebController { @Inject private UserLoginWebController loginController; - /** - * User instance - */ - private User user; - - @Override - public User getUser () { - return this.user; - } - @Override - public void setUser (final User user) { - this.user = user; - } + public boolean isProfileLinkVisible (final User user) { + // Check on user + 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 id + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); + } else if (user.getUserProfileMode() == null) { + // And another NPE ... + throw new NullPointerException("user.userProfileMode is null"); + } - @Override - public boolean isProfileLinkVisible () { // Default profile mode is not visible - ProfileMode profileMode = ProfileMode.INVISIBLE; - - // Is the user set? - if (this.getUser() instanceof User) { - // Get profile mode from user - profileMode = this.getUser().getUserProfileMode(); - } + ProfileMode profileMode = user.getUserProfileMode(); // Check all conditions (except for admin) // TODO: Add admin role somehow? diff --git a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebController.java b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebController.java index f3cc9d11..a9ad631f 100644 --- a/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebController.java +++ b/src/java/org/mxchange/addressbook/beans/profile/UserProfileWebController.java @@ -27,23 +27,11 @@ import org.mxchange.jusercore.model.user.User; public interface UserProfileWebController extends Serializable { /** - * Getter for user instance - *

- * @return User instance - */ - User getUser (); - - /** - * Setter for user instance + * Checks if the user profile link is visible *

* @param user User instance - */ - void setUser (final User user); - - /** - * Checks if the user profile link is visible *

* @return Whether the profile link is visible */ - boolean isProfileLinkVisible (); + boolean isProfileLinkVisible (final User user); } diff --git a/web/WEB-INF/templates/generic/user_profile_link.tpl b/web/WEB-INF/templates/generic/user_profile_link.tpl index faadd593..0bbe58a5 100644 --- a/web/WEB-INF/templates/generic/user_profile_link.tpl +++ b/web/WEB-INF/templates/generic/user_profile_link.tpl @@ -6,10 +6,8 @@ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"> - - - +