]> git.mxchange.org Git - addressbook-war.git/commitdiff
Added work-around for NPE "this.user is null". Not a fix!
authorRoland Haeder <roland@mxchange.org>
Fri, 23 Oct 2015 18:47:02 +0000 (20:47 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 23 Oct 2015 18:47:02 +0000 (20:47 +0200)
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java
web/login/login_start_sharing_addressbook.xhtml

index aefe771bd3fb6fbaf88e274dd4dd84421e127ab0..45eae1dd871a9c2037a72f4d0b0064394360d3f2 100644 (file)
@@ -102,8 +102,29 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle
 
                // Check all conditions (except for admin)
                // TODO: Add admin role somehow?
-               return ((profileMode.equals(ProfileMode.PUBLIC))
-                               || (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS)));
+               return ((profileMode.equals(ProfileMode.PUBLIC)) ||
+                                (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS)));
+       }
+
+       @Override
+       public boolean isProfileLinkVisibleByUser (final User user) {
+               // Is the user instance valid?
+               if (null == user) {
+                       // Throw NPE here
+                       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) {
+                       // Throw NPE again
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId()));
+               }
+
+               // Set it here
+               this.setUser(user);
+
+               // Ask other method
+               return this.isProfileLinkVisible();
        }
 
        @Override
index 12e04ebdecb912344057d2a84b90fc9df9220ddd..437c2d4c747df54a7ca6b88cd8b3d5dde83ce6ee 100644 (file)
@@ -33,6 +33,16 @@ public interface UserProfileWebRequestController extends Serializable {
         */
        boolean isProfileLinkVisible ();
 
+       /**
+        * Checks if given user's profile is visible to the currently logged-in
+        * user.
+        * <p>
+        * @param user User instance
+        * <p>
+        * @return Whether the profile link is visible
+        */
+       boolean isProfileLinkVisibleByUser (final User user);
+
        /**
         * Checks if the user profile link is visible
         * <p>
index 857df3f3f1692afa8b848530e2ebd606a1e1f0a7..8158d04a74512f514892fa958a0a8d5fd5da8d7e 100644 (file)
@@ -38,7 +38,7 @@
 
                                                <h:column>
                                                        <f:facet name="header">#{msg.LOGIN_START_SHARING_TITLE}</f:facet>
-                                                       <h:form acceptcharset="utf-8" id="startSharing" rendered="#{profileController.isProfileLinkVisible()}">
+                                                       <h:form acceptcharset="utf-8" id="startSharing" rendered="#{profileController.isProfileLinkVisibleByUser(user)}">
                                                                <h:commandButton class="submit" id="submit" value="#{msg.LOGIN_START_SHARING_BUTTON}" action="#{shareController.startSharing(user, addressbookController.addressbook)}" title="#{msg.LOGIN_START_SHARING_BUTTON_TITLE}" />
                                                        </h:form>
                                                </h:column>