- 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>
}
@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
}
// Ask other method
- return this.isProfileLinkVisible(u);
+ return this.isProfileLinkVisible();
}
}
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
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>
</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">