]> git.mxchange.org Git - jjobs-war.git/commitdiff
c:set is a trap:
authorRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 20:35:12 +0000 (21:35 +0100)
committerRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 20:35:12 +0000 (21:35 +0100)
- 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 <roland@mxchange.org>
nbproject/faces-config.NavData
src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestBean.java
src/java/org/mxchange/jjobs/beans/profile/UserProfileWebRequestController.java
web/WEB-INF/templates/generic/user_profile_link.tpl
web/login/login_shared_addressbooks.xhtml
web/login/login_start_sharing_addressbook.xhtml
web/user/show_addressbook.xhtml
web/user/user_list.xhtml

index 0cb544463d3f0405b8ca7f77bef9020e57e3e090..298bfc50a82fc997caae5cb3a3a53656c24b7570 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scene Scope="Project" version="2">
-       <Scope Scope="Faces Configuration Only"/>
-       <Scope Scope="Project"/>
-       <Scope Scope="All Faces Configurations"/>
+    <Scope Scope="Faces Configuration Only"/>
+    <Scope Scope="Project"/>
+    <Scope Scope="All Faces Configurations"/>
 </Scene>
index b692c7fc87e007dad826fe5721522201ff14deb4..1018a33c67d0259c0f77e2679e0403a94e4ebb6f 100644 (file)
@@ -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();
-       }
 }
index 34a5aa3737c6bbe438a9d4e17789e4f98f61d4fc..a953d540285c383914ecdd65c83165190535c547 100644 (file)
@@ -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
-        * <p>
-        * @return Whether the profile link is visible
-        */
-       boolean isProfileLinkVisible ();
-
        /**
         * Checks if the user profile link is visible
         * <p>
@@ -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
-        * <p>
-        * @return User instance
-        */
-       User getUser ();
-
-       /**
-        * Setter for user instance
-        * <p>
-        * @param user User instance
-        */
-       void setUser (final User user);
 }
index c142209e97cdaa673fa06a105fa989af513c7e32..037b83a4a6674bb72ba9350d10a0d17f927c2654 100644 (file)
@@ -5,12 +5,12 @@
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
 
-       <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty profileController.user}" />
+       <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty user}" />
 
-       <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" rendered="#{not empty profileController.user and not profileController.isProfileLinkVisible()}" />
+       <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" rendered="#{not empty user and not profileController.isProfileLinkVisibleByUser(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 id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}" rendered="#{not empty user and profileController.isProfileLinkVisibleByUser(user)}">
+               <h:outputText id="userName" value="#{user.userName}" />
+               <f:param name="userId" value="#{user.userId}" />
        </h:link>
 </ui:composition>
index e531374fde7a51db9bd333ec0dfec6ea49afd4f3..66f4c8ef26564180a5b71f71825f55f19d0f8b3a 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <ui:composition template="/WEB-INF/templates/login/login_base.tpl">
                <ui:define name="login_title">#{msg.PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS}</ui:define>
@@ -21,8 +20,6 @@
 
                                <div class="para">
                                        <h:dataTable id="sharedAddressbooks" var="share" value="#{shareController.allShares()}" headerClass="table_data_column" summary="#{msg.TABLE_SUMMARY_LOGIN_SHARED_ADDRESSBOOKS}" rendered="#{shareController.isSharingAddressbooks()}">
-                                               <c:set value="#{share.shareUserSharee}" target="#{profileController}" property="user" />
-
                                                <h:column>
                                                        <f:facet name="header">#{msg.SHARED_ADDRESSBOOK}</f:facet>
 
@@ -34,7 +31,9 @@
 
                                                <h:column>
                                                        <f:facet name="header">#{msg.SHAREE_USER_NAME}</f:facet>
-                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                               <ui:param name="user" value="#{share.shareUserSharee}" />
+                                                       </ui:include>
                                                </h:column>
 
                                                <h:column>
index f86110d8833c5b990145c8f697b36ee45e199d69..790ae681ddae4a2c3680acef87ff7d5c60442ed0 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <ui:composition template="/WEB-INF/templates/#{loginController.templateType}/#{loginController.templateType}_base.tpl">
                <ui:define name="login_title">#{msg.PAGE_TITLE_LOGIN_START_SHARING_ADDRESSBOOK}</ui:define>
@@ -32,7 +31,9 @@
 
                                                <h:column>
                                                        <f:facet name="header">#{msg.USER_NAME}</f:facet>
-                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                               <ui:param name="user" value="#{user}" />
+                                                       </ui:include>
                                                </h:column>
 
                                                <h:column>
index 7000aaedff5e97ac73edd7b280876525496c3acf..686605a068b6ba3d31579793315ea95c8c906021 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <f:metadata>
                <f:viewParam id="addressbookId" name="addressbookId" value="#{addressbookController.addressbookId}" required="true" requiredMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_MISSING}" converterMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_INVALID}" validatorMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_NOT_FOUND}">
@@ -23,8 +22,6 @@
 
                <ui:define name="content">
                        <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.isAddressbookLoaded()}">
-                               <c:set value="#{addressbookController.addressbookUser}" target="#{profileController}" property="user" />
-
                                <f:facet name="header">#{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}</f:facet>
 
                                <h:outputLabel for="addressbookId" class="table_label">#{msg.ADDRESSBOOK_ID}</h:outputLabel>
@@ -34,7 +31,9 @@
                                <h:outputText id="addressbookName" value="#{addressbookController.addressbookName}" />
 
                                <h:outputLabel for="userProfileLink" class="table_label">#{msg.ADDRESSBOOK_OWNER}</h:outputLabel>
-                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                       <ui:param name="user" value="#{addressbookController.addressbookUser}" />
+                               </ui:include>
 
                                <h:outputLabel for="addressbookCreated" class="table_label">#{msg.ADDRESSBOOK_CREATED}</h:outputLabel>
                                <h:outputFormat id="addressbookCreated" value="#{addressbookController.addressbook.addressbookCreated.time}" title="#{msg.ADDRESSBOOK_CREATED_TITLE}">
index 12f18f92afcecc8eee3656f0a08bd266dd9f6bef..8f5f4b63ab270ee1031d4cad511978e004a96192 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <ui:composition template="/WEB-INF/templates/#{loginController.templateType}/#{loginController.templateType}_base.tpl">
                <ui:define name="login_title">#{msg.PAGE_TITLE_USER_LIST}</ui:define>
                                </div>
 
                                <h:dataTable id="userList" var="user" value="#{userController.allVisibleUsers()}" headerClass="table_header_column25" summary="#{msg.TABLE_SUMMARY_USER_LIST}" rendered="#{userController.isVisibleUserFound()}">
-                                       <c:set value="#{share.shareUserSharee}" target="#{profileController}" property="user" />
                                        <h:column>
                                                <f:facet name="header">#{msg.USER_ID}</f:facet>
-                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                               <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.USER_NAME}</f:facet>
-                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                       <ui:param name="user" value="#{user}" />
+                                               </ui:include>
                                        </h:column>
 
                                        <h:column>