*/
package org.mxchange.addressbook.beans.profile;
+import java.text.MessageFormat;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
@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?
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);
}
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}" />