Foren

FacesContext.getCurrentInstance returns null after migration from6.1 to6.2

Peter Peter, geändert vor 6 Jahren.

FacesContext.getCurrentInstance returns null after migration from6.1 to6.2

New Member Beiträge: 2 Beitrittsdatum: 09.07.17 Neueste Beiträge
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.
 <h:form id="form" rendered="#{securityBean.roles['OrderReader'] ne null}"></h:form>
)


 public Map<string, string> getRoles() {

        Map<string, string> roles = new HashMap<string, string>();      
        FacesContext context = FacesContext.getCurrentInstance();
       
        ExternalContext ec = context.getExternalContext();

        Map requestMap = ec.getRequestMap();
        ThemeDisplay themeDisplay = (ThemeDisplay)requestMap.get(WebKeys.THEME_DISPLAY);

        try {

            final List<usergroup> userGroupList = themeDisplay.getUser()
                    .getUserGroups();

            for (UserGroup ug : userGroupList) {

                List<role> groupRoles = RoleLocalServiceUtil.getGroupRoles(ug
                        .getGroup().getGroupId());

                for (Role role : groupRoles) {
                    if (!roles.containsKey(role)) {
                        roles.put(role.getName(), "1");
                    }
                }
            }

            final List<role> roleList = themeDisplay.getUser().getRoles();

            for (Role item : roleList) {
                if (!roles.containsKey(item.getName())) {
                    roles.put(item.getName(), "1");
                }
            }
        } catch (Exception e) {
            logger.error("Can't get roles for the user:" + e.getMessage(), e);
            throw new RuntimeException(e);
        }

        return roles;

    }</role></role></usergroup></string,></string,></string,>


SecurityBean is a Spring’s bean.

<bean id="securityBean" class="app.common.SecurityBean" scope="session" lazy-init="true">
</bean>


It works in Liferay 6.1 but after migration to 6.2 FacesContext.getCurrentInstance() returns null. Please help resolve this.
Regards
thumbnail
Kyle Joseph Stiemann, geändert vor 6 Jahren.

RE: FacesContext.getCurrentInstance returns null after migration from6.1 to

Liferay Master Beiträge: 760 Beitrittsdatum: 14.01.13 Neueste Beiträge
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, geändert vor 6 Jahren.

RE: FacesContext.getCurrentInstance returns null after migration from6.1 to

New Member Beiträge: 2 Beitrittsdatum: 09.07.17 Neueste Beiträge
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
thumbnail
Kyle Joseph Stiemann, geändert vor 6 Jahren.

RE: FacesContext.getCurrentInstance returns null after migration from6.1 to

Liferay Master Beiträge: 760 Beitrittsdatum: 14.01.13 Neueste Beiträge
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
thumbnail
Kyle Joseph Stiemann, geändert vor 6 Jahren.

RE: FacesContext.getCurrentInstance returns null after migration from6.1 to

Liferay Master Beiträge: 760 Beitrittsdatum: 14.01.13 Neueste Beiträge
Please also post the version of the app server that you are running Liferay 6.2 on.