]> git.mxchange.org Git - addressbook-war.git/commitdiff
rewrote isProfileLinkVisible() as the previous attempt didn't work
authorRoland Haeder <roland@mxchange.org>
Fri, 16 Oct 2015 17:43:43 +0000 (19:43 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 16 Oct 2015 17:43:43 +0000 (19:43 +0200)
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebBean.java
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebController.java
web/WEB-INF/templates/generic/user_profile_link.tpl

index 520ef1709530a4a9950f7a2499f2ee7d6c64dfe0..6adc75d963366ef9bf4d097055b2ce18227cef0f 100644 (file)
@@ -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?
index f3cc9d11c18cea2c8d5a3ccec62853686d953db9..a9ad631f03ed214b9491a54fab066db148ac803b 100644 (file)
@@ -27,23 +27,11 @@ import org.mxchange.jusercore.model.user.User;
 public interface UserProfileWebController extends Serializable {
 
        /**
-        * Getter for user instance
-        * <p>
-        * @return User instance
-        */
-       User getUser ();
-
-       /**
-        * Setter for user instance
+        * Checks if the user profile link is visible
         * <p>
         * @param user User instance
-        */
-       void setUser (final User user);
-
-       /**
-        * Checks if the user profile link is visible
         * <p>
         * @return Whether the profile link is visible
         */
-       boolean isProfileLinkVisible ();
+       boolean isProfileLinkVisible (final User user);
 }
index faadd593cfe850e3de0fbd1da29c9c62e1b9e431..0bbe58a5a7dbcc53a4f1c2bba5100755d075287c 100644 (file)
@@ -6,10 +6,8 @@
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
 
-       <ui:param id="user" name="user" value="#{profileController.user}" />
-
        <c:choose>
-               <c:when test="#{profileController.isProfileLinkVisible()}">
+               <c:when test="#{profileController.isProfileLinkVisible(user)}">
                        <h:link id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}">
                                <h:outputText id="userName" value="#{user.userName}" />
                                <f:param name="userId" value="#{user.userId}" />