[Building Sakai] Display logged in user First Name in header area

Robert Long rlong at unicon.net
Wed Nov 6 11:09:14 PST 2013


Kim,

As small FYI, you can also get the user's first name from User.getFirstName() instead of parsing the display name for the first name.

--Bob

----
Robert Long
Software Engineer
Unicon, Inc.

----
M.A., Instructional Technology
Saginaw Valley State University

On Nov 6, 2013, at 1:55 PM, "Wilson, Kimberly" <wilsonk at mail.amc.edu> wrote:

> Hi everybody, I figured it out!
>  
> This is what I did:
> 1.      \portal\portal-impl\impl\src\java\org\sakaiproject\portal\charon\SkinnableCharonPortal.java
>  
> Created two variables (Line 1740):
> String removeLastName = null;
> String loginUserFirstName = null;
>  
> Used some string functions to get at the first name from the Display Name (Line 1806):
>  
> removeLastName = StringUtils.substringAfterLast(loginUserDispName," ");
> loginUserFirstName = StringUtils.removeEnd(loginUserDispName,removeLastName);
>  
> This way when there is a two part first name, like “Jo Anne”, both of those will be picked up
>  
> 2.      portal\portal-render-engine-impl\pack\src\webapp\vm\defaultskin\site.vm
> Line 82:
>  
> #if (${displayUserloginInfo})
>             <span id="loginUser">Welcome, ${loginUserFirstName} | </span>
> #end
>  
>  
> I also added this on Line 1868, not sure what it pertains to though – but maven produced an error without it:
> rcontext.put("loginUserFirstName", loginUserFirstName);
>  
> I used this page for reference:
> http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html
>  
> Also, this page was somewhat useful:
> http://grepcode.com/file/repo1.maven.org/maven2/org.sakaiproject.kernel/sakai-kernel-api/1.3.0-b03/org/sakaiproject/user/api/UserDirectoryService.java
>  
>  
>  
> Kim Wilson, MSCIS | Systems Analyst – IS Academic Systems | Albany Medical Center | 518-264-1055
>  
> <image001.jpg>
>  
> From: Wilson, Kimberly 
> Sent: Wednesday, November 6, 2013 10:21 AM
> To: 'sakai-dev at collab.sakaiproject.org'
> Subject: RE: Display logged in user First Name in header area
>  
> Thank you, everyone’s suggestions have been extremely helpful, but I still can’t get at the first name
>  
> I found the variables on the site.vm page are being set from this file:
> SkinnableCharonPortal.java
>  
> So I added this to define the first name variable:
>  
> String loginUserFirstName = null;
>  
> (and I noticed this is ok:  )
> boolean displayUserloginInfo = ServerConfigurationService.
> getBoolean("display.userlogin.info", true);
>  
>  
> But I can’t figure out how to display this information on my site to see what is contained in it:
> UserDirectoryService.getUser(userId)
>  
> I found this site:
> https://fisheye6.atlassian.com/browse/SakaiSVN/user/trunk/user-tool/tool/src/webapp/vm/user/chef_users_view.vm?r2=128776
> That contains this line:
>  $validator.escapeHtml($user.FirstName)
>  
> But I have tried various methods of setting the value with no luck so far and I’m getting errors in the maven build (around line 1800 of SkinnableCharonPortal.java):
> loginUserFirstName = Validator.escapeHtml(thisUser.FirstName);
> loginUserFirstName = Validator.escapeHtml(thisUser.getFirstName());
>  
> and put this in the site.vm in the mastLogin div:
>  
> #if (${displayUserloginInfo})
>             <span id="loginUser">Welcome, ${loginUserFirstName} | </span>
> #end
>  
> I’m still searching.  Any more help will be greatly appreciated!
>  
>  
> Kim Wilson, MSCIS | Systems Analyst – IS Academic Systems | Albany Medical Center | 518-264-1055
>  
> <image005.jpg>
>  
> From: Schauer, Christopher R [mailto:cschauer at txstate.edu] 
> Sent: Saturday, November 2, 2013 5:54 AM
> To: Wilson, Kimberly; sakai-dev at collab.sakaiproject.org
> Subject: RE: Display logged in user First Name in header area
>  
> Hi Kim,
>  
> One possibility would be to add it in 'portal/portal-render-engine-impl/pack/src/webapp/vm/neoskin/site.vm'. That is the velocity file that is used to render the header area. The handler for that view is at 'portal/portal-impl/impl/src/java/org/sakaiproject/portal/charon/handlers/SiteHandler.java' and you can add the user's first name to the context there. The userId is in the session and you can use UserDirectoryService.getUser(userId) to get the User object for the current user.
>  
> -Chris
>  
> From: sakai-dev-bounces at collab.sakaiproject.org [sakai-dev-bounces at collab.sakaiproject.org] on behalf of Wilson, Kimberly [wilsonk at mail.amc.edu]
> Sent: Friday, November 01, 2013 3:31 PM
> To: sakai-dev at collab.sakaiproject.org
> Subject: [Building Sakai] Display logged in user First Name in header area
> 
> Hi:
>  
> I’ve been modifying our Sakai portal.css for our 2.9.3 upcoming release
>  
> I need to figure out how to display the logged in user’s first name in a Welcome message in the header of the page
>  
> Does anyone know how to do this?  Maybe with jQuery or Javascript?
>  
> I don’t know how to call the first name from the logged in user information.
>  
> Thanks!
>  
> Kim Wilson, MSCIS | Systems Analyst – IS Academic Systems | Albany Medical Center | 518-264-1055
>  
> <image006.jpg>
>  
> ----------------------------------------- CONFIDENTIALITY NOTICE: This email and any attachments may contain confidential information that is protected by law and is for the sole use of the individuals or entities to which it is addressed. If you are not the intended recipient, please notify the sender by replying to this email and destroying all copies of the communication and attachments. Further use, disclosure, copying, distribution of, or reliance upon the contents of this email and attachments is strictly prohibited. To contact Albany Medical Center, or for a copy of our privacy practices, please visit us on the Internet at www.amc.edu.
> 
> ----------------------------------------- CONFIDENTIALITY NOTICE: This email and any attachments may contain confidential information that is protected by law and is for the sole use of the individuals or entities to which it is addressed. If you are not the intended recipient, please notify the sender by replying to this email and destroying all copies of the communication and attachments. Further use, disclosure, copying, distribution of, or reliance upon the contents of this email and attachments is strictly prohibited. To contact Albany Medical Center, or for a copy of our privacy practices, please visit us on the Internet at www.amc.edu.
> 
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> 
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20131106/8d39c4e0/attachment.html 


More information about the sakai-dev mailing list