Forums de discussion

Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListener

Timothy Esposito, modifié il y a 10 années.

Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListener

New Member Publications: 6 Date d'inscription: 07/10/12 Publications récentes
I have a Liferay Portlet app that was broken on JBoss AS 7.1.1 with an older version of Liferay for other reasons, but I've recently migrated to TomEE+ 1.6.2 on Tomcat 7.0.47 and have Liferay Faces 3.2.4-ga5 snapshot integrated 2.1.13. TomEE+ is using MyFaces 2.1.13. The JSF pages are rendering, but I can not resolve the following exception.


21:12:53,578 ERROR [LiferayFacesContext:41] Instance not initialized -- caller might be static
21:12:53,578 ERROR [LiferayLocalePhaseListener:87] 
java.lang.NullPointerException
	at com.liferay.faces.portal.lifecycle.LiferayLocalePhaseListener.setLocale(LiferayLocalePhaseListener.java:67)
	at com.liferay.faces.portal.lifecycle.LiferayLocalePhaseListener.beforePhase(LiferayLocalePhaseListener.java:55)
	at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersBefore(PhaseListenerManager.java:77)
	at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:234)
	at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:227)
	at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:85)
	at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:112)
	at javax.portlet.faces.GenericFacesPortlet.doView(GenericFacesPortlet.java:255)
	at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
	at javax.portlet.faces.GenericFacesPortlet.doDispatch(GenericFacesPortlet.java:204)
	at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
	at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
	at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
	at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
	at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:604)
	at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:677)
	at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:379)
	at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1237)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:57)
	at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
	at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
	at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:655)
	at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:138)
	at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
	at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
	at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
	at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:120)
	at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
	at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:174)
	at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
	at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
	at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
	at java.lang.Thread.run(Thread.java:744)


I tried setting the Locale manually using what is suggested at http://wiki.apache.org/myfaces/Liferay. Nothing seems to get rid of it. Below is an ugly version of my code if anyone wants to see it.


package com.emergentspace.gems.web;

import java.util.Locale;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

/**
 * Set the locale to solve NPE at com.liferay.faces.portal.lifecycle.LiferayLocalePhaseListener.setLocale(LiferayLocalePhaseListener.java:67)
 * Parts copied from http://wiki.apache.org/myfaces/Liferay
 */
public class LocaleFixPhaseListener implements PhaseListener {

    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }

    /**
     * Called to update within Portlet environment the language of Portal.
     *
     * @see PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
     */
    public void beforePhase(final PhaseEvent evt) {
        //System.out.println("SETTING LOCALE IN FACES CONTEXT TO " + Locale.getDefault() + "; PhaseId=" + PhaseId.RENDER_RESPONSE);
        //evt.getFacesContext().getViewRoot().setLocale(Locale.getDefault());
        
        //if (PhaseId.RENDER_RESPONSE.equals(evt.getPhaseId())) {
            /*final Object request = evt.getFacesContext().getExternalContext().getRequest();
            if (request instanceof RenderRequest) {
                System.out.println("ACTUALLY SETTING LOCALE NOW!!!");
                evt.getFacesContext().getViewRoot().setLocale(Locale.getDefault());
                LocalizationUtil.getLocalization();
            }*/
        //}
        
        try {
            FacesContext fc = evt.getFacesContext();
            
            if (fc == null) {
                System.out.println("FACES CONTEXT IS NULL; " + evt);
                return;
            }
            
            System.out.println("renderResponse=" + fc.getRenderResponse() + ", renderComplete" + fc.getResponseComplete());
            UIViewRoot view = fc.getViewRoot();
            
            if (view == null) {
                System.out.println("FACES CONTEXT VIEW ROOT IS NULL; " + evt);
                return;
            }
            
            view.setLocale(Locale.getDefault());
            System.out.println("SET LOCALE IN FACES CONTEXT TO " + Locale.getDefault() + "; PhaseId=" + PhaseId.RENDER_RESPONSE);
        } catch (Exception e) {
            System.out.println("FAILED TO SET LOCALE IN FACES CONTEXT TO " + Locale.getDefault() + "; PhaseId=" + PhaseId.RENDER_RESPONSE + "; " + e);
            e.printStackTrace();
        }
    }

    public void afterPhase(PhaseEvent event) {
    }
}


Is there any way to resolve this issue? Also, I see that there is only 1 open issue left on JIRA for 3.2.4. Is the planned release coming soon?

I was also looking at this issue: https://issues.liferay.com/browse/FACES-1252. Is there a way I can simply remove the LiferayLocalePhaseListener from the LifecycleFactoryImpl

Thanks,
Tim
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListen

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Due to some portlet incompatibilities with MyFaces, we are currently not able to support MyFaces for JSF portlets.

I would recommend that you remove MyFaces from your TomEE installation and replace it with Mojarra. For more info, see the Upgrading Mojarra in Apache Tomcat wiki article.
Timothy Esposito, modifié il y a 10 années.

RE: Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListen

New Member Publications: 6 Date d'inscription: 07/10/12 Publications récentes
Neil, Thanks for your response. I will give your suggestion a try. Ironically, my motivation for switching off of JBoss/Mojarra to TomEE+/MyFaces was that Mojarra seemed a bit flaky. We also have a similar setup on TomeEE+/MyFaces with Liferay 6.1 and it is running like a charm. It is also worth noting that I am using PrimeFaces 4.0.
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListen

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Hi Timothy,

I just wanted to mention that Manfred Reim (one of the maintainers of Mojarra at Oracle) recently tweeted that the Mojarra bug count is down to zero. So if you run into any problems with Mojarra, please create a ticket. Since there are no open bugs left, any new bugs filed should get good visibility.

Kind Regards,

Neil
Timothy Esposito, modifié il y a 10 années.

RE: Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListen

New Member Publications: 6 Date d'inscription: 07/10/12 Publications récentes
For reference, switching to Mojarra 2.1.27 with the suggested edits from the Liferay wiki page fixed the issue. Thank you for your help Neil.
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: Liferay Faces 3.2.4-ga5 on TomEE+ 1.6.2 NPE in LiferayLocalePhaseListen

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
It was my pleasure Timothy. Glad to hear that it is working for you now, and thanks for using Liferay Faces emoticon