| ThemeDisplayManagedBean.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
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 }