Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Peter Peter
FacesContext.getCurrentInstance returns null after migration from6.1 to6.2
July 10, 2017 12:01 AM
Answer

Peter Peter

Rank: New Member

Posts: 2

Join Date: July 9, 2017

Recent Posts

We need to get a list of roles of current user so we implemented bean called SecurityBean contains method getRoles(). This method is used in our portlets(e. g.
1 <h:form id="form" rendered="#{securityBean.roles['OrderReader'] ne null}">
)


 1 public Map<String, String> getRoles() {
 2
 3        Map<String, String> roles = new HashMap<String, String>();      
 4        FacesContext context = FacesContext.getCurrentInstance();
 5      
 6        ExternalContext ec = context.getExternalContext();
 7
 8        Map requestMap = ec.getRequestMap();
 9        ThemeDisplay themeDisplay = (ThemeDisplay)requestMap.get(WebKeys.THEME_DISPLAY);
10
11        try {
12
13            final List<UserGroup> userGroupList = themeDisplay.getUser()
14                    .getUserGroups();
15
16            for (UserGroup ug : userGroupList) {
17
18                List<Role> groupRoles = RoleLocalServiceUtil.getGroupRoles(ug
19                        .getGroup().getGroupId());
20
21                for (Role role : groupRoles) {
22                    if (!roles.containsKey(role)) {
23                        roles.put(role.getName(), "1");
24                    }
25                }
26            }
27
28            final List<Role> roleList = themeDisplay.getUser().getRoles();
29
30            for (Role item : roleList) {
31                if (!roles.containsKey(item.getName())) {
32                    roles.put(item.getName(), "1");
33                }
34            }
35        } catch (Exception e) {
36            logger.error("Can't get roles for the user:" + e.getMessage(), e);
37            throw new RuntimeException(e);
38        }
39
40        return roles;
41
42    }


SecurityBean is a Spring’s bean.
1
2<bean id="securityBean"
3          class="app.common.SecurityBean"
4          scope="session" lazy-init="true">
5</bean>


It works in Liferay 6.1 but after migration to 6.2 FacesContext.getCurrentInstance() returns null. Please help resolve this.
Regards
Kyle Joseph Stiemann
RE: FacesContext.getCurrentInstance returns null after migration from6.1 to
July 10, 2017 5:45 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 573

Join Date: January 14, 2013

Recent Posts

Hi Peter,
Can you try upgrading to the latest Liferay Faces release? You can use liferayfaces.org to discover the correct versions for your project. Just select Liferay Portal 6.2 from the drop-down menu. Please let us know if that fixes your issue.

- Kyle
Peter Peter
RE: FacesContext.getCurrentInstance returns null after migration from6.1 to
July 12, 2017 2:24 AM
Answer

Peter Peter

Rank: New Member

Posts: 2

Join Date: July 9, 2017

Recent Posts

Hi
I've written too simplified description. This description works fine, but
in our application, process is a little more complicated.
The application is split into two deployments, app-fe.war and app-be.ear
In app-fe.war there is a SecurityBean bean and a common-model.jar contains a class UserRuntimeInformation, which contains a getRoles () method described in the previous post. The common-model.jar is also put to app-be.ear - perhaps it is important.
SecurityBean calls the UserRuntimeInformation.getRoles method that executes FacesContext.getCurrentInstance () and here comes null.
Perhaps the problem is with class loading, but I do not know how to solve it.
Liferay 6.2 must behave differently to 6.1
Regards
Peter
Kyle Joseph Stiemann
RE: FacesContext.getCurrentInstance returns null after migration from6.1 to
July 12, 2017 8:51 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 573

Join Date: January 14, 2013

Recent Posts

Hi Peter,
In order to help us reproduce the issue, could you please attach the shortest, simplest maven project that builds an ear (including a simplified war and the jars that you mentioned) and reproduces your issue in Liferay 6.2?

Thanks,
- Kyle
Kyle Joseph Stiemann
RE: FacesContext.getCurrentInstance returns null after migration from6.1 to
July 12, 2017 9:02 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 573

Join Date: January 14, 2013

Recent Posts

Please also post the version of the app server that you are running Liferay 6.2 on.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!