2 Replies Latest reply on Mar 24, 2009 4:37 PM by J Crisp

    struggling to get user family name and role into jsp file

    J Crisp Newbie

      Is there a way from the header.jsp to display the family name of the user? I am trying to customize the portal-core.war and need to display the first and last name of the user.

      Also what about getting the role? Let's say I only want to display a link in the header.jsp based on a role of admin?

      I don't have any problems getting this info when I am working with Seam but with straight jsp I am struggling to find the answers.

      Thanks in advance for any help!

        • 1. Re: struggling to get user family name and role into jsp fil
          Andy Pemberton Newbie

          What version of JBoss Portal are you using? In Portal 2.6, your PageCustomizerInterceptor stores the userProfile as a request attribute:

          Controller controller = controllerCtx.getController();
          Map userProfile = controllerCtx.getUserProfile();
          request.setAttribute("org.jboss.portal.header.USER_PROFILE", userProfile);


          You can then access attributes from the user profile in your header.jsp:

          <c:out value="${requestScope['org.jboss.portal.header.USER_PROFILE']['user.name.family']}" />


          If you're on Portal 2.7, the process should be about the same. Check the reference docs for info on accessing the UserProfile in 2.7: http://docs.jboss.org/jbportal/v2.7.1/referenceGuide/html/identity.html

          • 2. Re: struggling to get user family name and role into jsp fil
            J Crisp Newbie

            Thanks apemberton for pointing me in the right direction!

            In Portal 2.7 it changed a little bit. Here is what I did inside the jsp to get the first and last name:

            <%
            
            UserProfileModule userProfileModule = (UserProfileModule) new InitialContext().lookup("java:portal/UserProfileModule");
            
            UserModule userModule = (UserModule) new InitialContext().lookup("java:portal/UserModule");
            
            User user = userModule.findUserByUserName(principal.getName());
            
            String lastName = (String) userProfileModule.getProperty(user, User.INFO_USER_NAME_FAMILY);
            
            String firstName = (String) userProfileModule.getProperty(user, User.INFO_USER_NAME_GIVEN);
            
            %>