]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Tue, 20 Oct 2015 08:52:21 +0000 (10:52 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 20 Oct 2015 09:09:18 +0000 (11:09 +0200)
- rewrote isProfileLinkVisible() to not accept an instance and use the current (in bean set) instance instead
- well, don't use c:bla in your JSF pages
- updated jar(s)
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcontacts-lib.jar
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java
web/WEB-INF/templates/generic/user_profile_link.tpl
web/login/login_start_sharing_addressbook.xhtml

index 4bcab60630b0e9a2e35ba531a7fc870b20c03b36..811eebfffcb34d12c74b016b7ce39f88ce4471d9 100644 (file)
Binary files a/lib/jcontacts-lib.jar and b/lib/jcontacts-lib.jar differ
index 5e7d87c325604b9c0bbb5e9633c5a52eea406352..0869a84bd7e91dd6ecb54cad62bde36cb583c0f7 100644 (file)
@@ -69,28 +69,41 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle
        }
 
        @Override
-       public boolean isProfileLinkVisible (final User user) {
+       public boolean isProfileLinkVisible () {
                // Check on user
-               if (null == user) {
-                       // Throw NPE
-                       throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("user.userId is null"); //NOI18N
-               } else if (user.getUserId() < 1) {
-                       // Invalid id
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
-               } else if (user.getUserProfileMode() == null) {
-                       // And another NPE ...
-                       throw new NullPointerException("user.userProfileMode is null"); //NOI18N
+               if (null == this.getUser()) {
+                       /*
+                        * 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) {
+                       /*
+                        * 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) {
+                       /*
+                        * 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) {
+                       /*
+                        * Possibly an out-dated user profile is being used. This should not
+                        * happen.
+                        */
+                       throw new NullPointerException("this.user.userProfileMode is null"); //NOI18N
                }
 
-               // Default profile mode is not visible
-               ProfileMode profileMode = user.getUserProfileMode();
+               // Get profile mode from user instance (safe now)
+               ProfileMode profileMode = this.getUser().getUserProfileMode();
 
                // 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
@@ -116,6 +129,6 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle
                }
 
                // Ask other method
-               return this.isProfileLinkVisible(u);
+               return this.isProfileLinkVisible();
        }
 }
index 5da13a3af7bedb4c9edb9441b66087de3d1b8e28..12e04ebdecb912344057d2a84b90fc9df9220ddd 100644 (file)
@@ -27,13 +27,11 @@ import org.mxchange.jusercore.model.user.User;
 public interface UserProfileWebRequestController extends Serializable {
 
        /**
-        * Checks if the user profile link is visible
-        * <p>
-        * @param user User instance
+        * Checks if the current user profile link is visible
         * <p>
         * @return Whether the profile link is visible
         */
-       boolean isProfileLinkVisible (final User user);
+       boolean isProfileLinkVisible ();
 
        /**
         * Checks if the user profile link is visible
index bef7fcd54972e9cacd721f5b58674b65e7665acc..379c763e8906efb52638fc4ab6f4d29e3126757a 100644 (file)
@@ -3,24 +3,12 @@
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
-       xmlns:ui="http://java.sun.com/jsf/facelets"
-       xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-       <h:outputText value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{not empty loginController.}"
-       <c:choose>
-               <c:when test="#{user == null}">
-                       <h:outputText class="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" />
-               </c:when>
-
-               <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}" />
-                       </h:link>
-               </c:when>
-
-               <c:otherwise>
-                       <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" />
-               </c:otherwise>
-       </c:choose>
+       <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty profileController.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>
+       <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" />
 </ui:composition>
index d9c930b2f01f88ccff0077e55588927e25f91726..6704fb30ffaa8be9740d07bc802f4d6d3203b9c6 100644 (file)
                                </div>
 
                                <div class="para">
-                                       <c:choose>
-                                               <c:when test="#{loginController.isUserLoggedIn() and not loginController.isInvisible()}">
-                                                       <h:dataTable id="userList" headerClass="table_header_column" var="user" value="#{addressbookController.allUsersNotSharing()}">
-                                                               <h:column>
-                                                                       <f:facet name="header">#{msg.USER_ID}</f:facet>
-                                                                       <h:outputText value="#{user.userId}" />
-                                                               </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:param name="user" value="#{user}" />
-                                                                       </ui:include>
-                                                               </h:column>
-
-                                                               <h:column>
-                                                                       <f:facet name="header">#{msg.LOGIN_START_SHARING_TITLE}</f:facet>
-                                                                       <h:form acceptcharset="utf-8" id="startSharing" rendered="#{profileController.isProfileLinkVisible(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>
-                                                       </h:dataTable>
-                                               </c:when>
-                                               <c:when test="#{not loginController.isUserLoggedIn()}">
-                                                               <h:outputText id="ownProfileInvible" class="notice" value="#{msg.USER_NOT_LOGGED_IN}" />
-                                               </c:when>
-                                               <c:otherwise>
-                                                       <h:outputText id="ownProfileInvible" class="notice" value="#{msg.LOGIN_OWN_PROFILE_INVISIBLE}" />
-                                               </c:otherwise>
-                                       </c:choose>
+                                       <h:dataTable id="userList" headerClass="table_header_column" var="user" value="#{addressbookController.allUsersNotSharing()}" rendered="#{loginController.isUserLoggedIn() and not loginController.isInvisible()}">
+                                               <f:setPropertyActionListener target="#{user}" value="#{profileController.user}" />
+                                               <h:column>
+                                                       <f:facet name="header">#{msg.USER_ID}</f:facet>
+                                                       <h:outputText value="#{user.userId}" />
+                                               </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:param name="user" value="#{user}" />
+                                                       </ui:include>
+                                               </h:column>
+
+                                               <h:column>
+                                                       <f:facet name="header">#{msg.LOGIN_START_SHARING_TITLE}</f:facet>
+                                                       <h:form acceptcharset="utf-8" id="startSharing" rendered="#{profileController.isProfileLinkVisible()}">
+                                                               <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>
+                                       </h:dataTable>
+
+                                       <h:outputText id="ownProfileInvible" class="notice" value="#{msg.USER_NOT_LOGGED_IN}" rendered="#{not loginController.isUserLoggedIn()}" />
+
+                                       <h:outputText id="ownProfileInvible" class="notice" value="#{msg.LOGIN_OWN_PROFILE_INVISIBLE}" />
                                </div>
 
                                <div class="table_footer">