| ThemeDisplayManagedBean.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.util.bridges.jsf.common;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.GetterUtil;
20 import com.liferay.portal.model.User;
21 import com.liferay.portal.service.UserLocalServiceUtil;
22
23 import javax.faces.context.FacesContext;
24
25 /**
26 * <a href="ThemeDisplayManagedBean.java.html"><b><i>View Source</i></b></a>
27 *
28 * <p>
29 * This class is designed to be a convenient JSF managed bean that can be used
30 * to get portal related information (such as the user's time zone).
31 * </p>
32 *
33 * @author Neil Griffin
34 */
35 public class ThemeDisplayManagedBean {
36
37 public User getUser() {
38 FacesContext facesContext = FacesContext.getCurrentInstance();
39
40 String remoteUser = facesContext.getExternalContext().getRemoteUser();
41
42 try {
43 long userId = GetterUtil.getLong(remoteUser);
44
45 return UserLocalServiceUtil.getUserById(userId);
46 }
47 catch (Exception e) {
48 _log.error(e, e);
49 }
50
51 return null;
52 }
53
54 private static Log _log = LogFactoryUtil.getLog(User.class);
55
56 }