From: Roland Haeder Date: Mon, 15 Feb 2016 20:35:12 +0000 (+0100) Subject: c:set is a trap: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2fd41fa9780ec7b91f1364bb5485302c142677f1;p=jjobs-war.git c:set is a trap: - c:set is being executed in an other life-cycle that when h:dataTable is rendered - this causes a null value always being set in the target (backing) bean - instead you need to use ui:param within ui:include and use #{foo} for accessing it, even when your IDE is not showing it (as in that file's scope it doesn't "know" about the parameter). Signed-off-by: Roland Häder --- diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index 0cb54446..298bfc50 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -1,6 +1,6 @@ - - - + + + diff --git a/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestBean.java index b692c7fc..1018a33c 100644 --- a/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestBean.java @@ -47,11 +47,6 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle @Inject private UserLoginWebSessionController loginController; - /** - * User instance - */ - private User user; - /** * User controller */ @@ -59,97 +54,63 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle private UserWebSessionController userController; @Override - public User getUser () { - return this.user; - } + public boolean isProfileLinkVisibleById (final Long userId) { + // Init user instance + User u = null; - @Override - public void setUser (final User user) { - this.user = user; + try { + // Try to get it + u = this.userController.lookupUserById(userId); + } catch (final UserNotFoundException ex) { + // Throw again + throw new FaceletException(ex); + } + + // Is it null? + if (null == u) { + // Not found, not visible. + return false; + } + + // Ask other method + return this.isProfileLinkVisibleByUser(u); } @Override - public boolean isProfileLinkVisible () { + public boolean isProfileLinkVisibleByUser (final User user) { // Check on user - if (this.getUser() == null) { + if (user == null) { /* * 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) { + throw new NullPointerException("user is null"); //NOI18N + } else if (user.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) { + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.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) { + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N + } else if (user.getUserProfileMode() == null) { /* * Possibly an out-dated user profile is being used. This should not * happen. */ - throw new NullPointerException("this.user.userProfileMode is null"); //NOI18N + throw new NullPointerException("user.userProfileMode is null"); //NOI18N } // Get profile mode from user instance (safe now) - ProfileMode profileMode = this.getUser().getUserProfileMode(); + ProfileMode profileMode = user.getUserProfileMode(); // Check all conditions (except for admin) // TODO: Add admin role somehow? return ((profileMode.equals(ProfileMode.PUBLIC)) || (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS))); } - - @Override - public boolean isProfileLinkVisibleById (final Long userId) { - // Init user instance - User u = null; - - try { - // Try to get it - u = this.userController.lookupUserById(userId); - } catch (final UserNotFoundException ex) { - // Throw again - throw new FaceletException(ex); - } - - // Set it here - this.setUser(u); - - // Is it null? - if (null == u) { - // Not found, not visible. - return false; - } - - // Ask other method - return this.isProfileLinkVisible(); - } - - @Override - public boolean isProfileLinkVisibleByUser (final User user) { - // Is it correctly set? - 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 user id set - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); - } - - // Set user here - this.setUser(user); - - // Ask other method - return this.isProfileLinkVisible(); - } } diff --git a/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestController.java index 34a5aa37..a953d540 100644 --- a/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestController.java @@ -26,13 +26,6 @@ import org.mxchange.jusercore.model.user.User; */ public interface UserProfileWebRequestController extends Serializable { - /** - * Checks if the current user profile link is visible - *

- * @return Whether the profile link is visible - */ - boolean isProfileLinkVisible (); - /** * Checks if the user profile link is visible *

@@ -50,18 +43,4 @@ public interface UserProfileWebRequestController extends Serializable { * @return Whether the user's profile is visible */ boolean isProfileLinkVisibleByUser (final User user); - - /** - * Getter for user instance - *

- * @return User instance - */ - User getUser (); - - /** - * Setter for user instance - *

- * @param user User instance - */ - void setUser (final User user); } diff --git a/web/WEB-INF/templates/generic/user_profile_link.tpl b/web/WEB-INF/templates/generic/user_profile_link.tpl index c142209e..037b83a4 100644 --- a/web/WEB-INF/templates/generic/user_profile_link.tpl +++ b/web/WEB-INF/templates/generic/user_profile_link.tpl @@ -5,12 +5,12 @@ xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> - + - + - - - + + + diff --git a/web/login/login_shared_addressbooks.xhtml b/web/login/login_shared_addressbooks.xhtml index e531374f..66f4c8ef 100644 --- a/web/login/login_shared_addressbooks.xhtml +++ b/web/login/login_shared_addressbooks.xhtml @@ -3,8 +3,7 @@ + xmlns:f="http://xmlns.jcp.org/jsf/core"> #{msg.PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS} @@ -21,8 +20,6 @@

- - #{msg.SHARED_ADDRESSBOOK} @@ -34,7 +31,9 @@ #{msg.SHAREE_USER_NAME} - + + + diff --git a/web/login/login_start_sharing_addressbook.xhtml b/web/login/login_start_sharing_addressbook.xhtml index f86110d8..790ae681 100644 --- a/web/login/login_start_sharing_addressbook.xhtml +++ b/web/login/login_start_sharing_addressbook.xhtml @@ -3,8 +3,7 @@ + xmlns:f="http://xmlns.jcp.org/jsf/core"> #{msg.PAGE_TITLE_LOGIN_START_SHARING_ADDRESSBOOK} @@ -32,7 +31,9 @@ #{msg.USER_NAME} - + + + diff --git a/web/user/show_addressbook.xhtml b/web/user/show_addressbook.xhtml index 7000aaed..686605a0 100644 --- a/web/user/show_addressbook.xhtml +++ b/web/user/show_addressbook.xhtml @@ -3,8 +3,7 @@ + xmlns:f="http://xmlns.jcp.org/jsf/core"> @@ -23,8 +22,6 @@ - - #{msg.TABLE_HEADER_SHOW_ADDRESSBOOK} #{msg.ADDRESSBOOK_ID} @@ -34,7 +31,9 @@ #{msg.ADDRESSBOOK_OWNER} - + + + #{msg.ADDRESSBOOK_CREATED} diff --git a/web/user/user_list.xhtml b/web/user/user_list.xhtml index 12f18f92..8f5f4b63 100644 --- a/web/user/user_list.xhtml +++ b/web/user/user_list.xhtml @@ -3,8 +3,7 @@ + xmlns:f="http://xmlns.jcp.org/jsf/core"> #{msg.PAGE_TITLE_USER_LIST} @@ -20,15 +19,18 @@
- #{msg.USER_ID} - + + + #{msg.USER_NAME} - + + +