5 Replies Latest reply on Aug 27, 2009 9:54 AM by Tim Evers

    Simple question - How to change Welcome, <username> after log-in (not in header)

    Val Sw Expert
      There is Welcome, <username> message displayed immediately after login (I am not referring to Header menu welcome message).

      -- I just need to replace  Welcome, <username> with Welcome, <firstName lastName> after login, don't want to {identity.username}"
      Welcome, <username> is displayed after login, I think it is read from "messages_en.properties" - org.jboss.seam.loginSuccessful=Welcome, #0
      How can I change here as I have done in menu.xhtml below.

      I am able to change the same in header Menu (menu.xhtml)
      <rich:toolBarGroup location="right">
           <!--<h:outputText value="Welcome, #{identity.username}!" rendered="#{identity.loggedIn}"/>-->
           <h:outputText value="Welcome, #{getUserDetails.users.firstName} #{getUserDetails.users.lastName}!" rendered="#{identity.loggedIn}"/>
           <s:link view="/login.xhtml" value="" rendered="#{not identity.loggedIn}" disabled="true"/>
           <s:link view="/home.xhtml" action="#{identity.logout}" value="Logout" rendered="#{identity.loggedIn}"/>
      </rich:toolBarGroup>
        • 1. Re: Simple question - How to change Welcome, <username> after log-in (not in header)
          Val Sw Expert
          Adding to above mail, please suggest how can I track

          org.jboss.seam.loginSuccessful=Welcome, #0 in "messages_en.properties"
          • 2. Re: Simple question - How to change Welcome, <username> after log-in (not in header)
            Tim Evers Master

            To override the message:


            1. Create a properties file eg security_messages.properties
            2. In this file put org.jboss.seam.loginSuccessful= (to override the seam message) and then put in your own message.
            eg


            org.jboss.seam.loginSuccessful=
            my.custom.welcome.message=Welcome #0 #1
            


            3. Load this properties file in your app, this requires you to modify components.xml
            eg (you will need to fix the directory based on where you put this in your app etc


            <core:resource-loader>
                <core:bundle-names>
                    <value>bundles/security_messages</value>
                </core:bundle-names>
            </core:resource-loader>
            



            Last but not least. In your authenticate method you need to add your custom message when the user successfully logs in so...


            public boolean authenticate() {
               ....(logic to check if valid user
               if (validUser) {
                    FacesMessagesUtils.addInfoFromBundle(
                        "my.custom.welcome.message", 
                        loggedInUser.getFirstName(), 
                        loggedInUser.getLastName());
                    return true;
                }
            

            • 3. Re: Simple question - How to change Welcome, <username> after log-in (not in header)
              Val Sw Expert
              Thanks for the response Tim, we will try to implement the changes, for the time being as we needed to display the first & last name so I changed "org.jboss.seam.loginSuccessful=Welcome, #0"
              to
              org.jboss.seam.loginSuccessful=Welcome, #{getUsers.users.firstName} #{getUsers.users.lastName}
              where getUsers is a simple bean which returns users object.
              • 4. Re: Simple question - How to change Welcome, <username> after log-in (not in header)
                anca anton Newbie
                I am not sure these details matter, but I am using Seam 2.1.1 and Richfaces 3.2.2.
                I have tried Tim's solution but it hasn't quite worked for me: all the messages.properties file were ignored.
                So in the end, after trying more solutions, the one that worked for me is:

                - in the Authenticator class - 'authenticate' method I added:
                        facesMessages.addFromResourceBundle("my.custom.welcome.message", loggedUser.getContactUser().getUserFirstName(), loggedUser.getContactUser().getUserLastName());
                - in messages_x.properties I added the tags:
                        org.jboss.seam.loginSuccessful=
                        my.custom.welcome.message=Bienvenue, \#0 \#1       
                • 5. Re: Simple question - How to change Welcome, <username> after log-in (not in header)
                  Tim Evers Master

                  Unless I'm missing something you are using the solution I said, but using the default location for you .properties file.


                  If your properties files are being ignored then the chances are that you are not loading them correctly. (Wrong path/spelling etc)


                  Anyways, I'm glad it's working for you! :D