NPE at Application Start As WidgetBuilder is null

UI Components for JSF
Bardioc
Posts: 85
Joined: 21 Sep 2011, 08:10
Location: Stuttgart, Germany
Contact:

06 Dec 2012, 10:11

Hello,

our application is tested against Primefaces (TRUNK) to determine regressions. It contains the following third party libraries:

Code: Select all

myfaces-extcdi-bundle-jsf20 (1.0.6)
myfaces-extval-core (2.0.6)
myfaces-extval-bean-validation (2.0.6)
myfaces-extval-property-validation (2.0.6)
primefaces-3.5 (revision 8433)
Myfaces is used as JSF provider in Version 2.0 (as shipped with IBM WebSphere 8.0.0.4)

With this configuration our application does not longer start, but ends with a NPE. If we change back to primefaces-3.5-SNAPSHOT (which is an older revision) it works.

The exception thrown is:

Code: Select all

java.lang.NullPointerException
at org.primefaces.component.dialog.DialogRenderer.encodeScript(DialogRenderer.java:51)
at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.java:43)
at org.apache.myfaces.extensions.validator.core.renderkit.ExtValLazyRendererProxy.encodeEnd(ExtValLazyRendererProxy.java:76)
at org.apache.myfaces.extensions.validator.core.renderkit.ExtValRendererWrapper.encodeEnd(ExtValRendererWrapper.java:358)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:535)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:626)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:622)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:622)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1320)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:59)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:59)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
...
We tracked this down as the WidgetBuilder is not yet initialized. The new revision seems to utilize a system event listener to initialize the widget builder:

Code: Select all

<system-event-listener>
    <source-class>javax.faces.component.UIViewRoot</source-class>
    <system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
    <system-event-listener-class>org.primefaces.webapp.PreRenderViewListener</system-event-listener-class>
</system-event-listener>
We figured out that none of the Primefaces-related system event listeners have been called before the 'encodeScript' method of the DialogRenderer is called, thus leading to the NPE. This even is the case if we add the very same system event listener to the applications faces-config.xml.

It seems that Primefaces no longer works properly together with myfaces-extval. It is currently unsure why none of the system event listeners are called beforehand and if this is a problem with primefaces or myfaces-extval.

Can you possibly shed some light on this?

Thank you,

Best regards,

Heiko
PrimeFaces 4.0, 5.0-SNAPSHOT
MyFaces 2.0.x (as part of WebSphere Application Server 8)
WebSphere Application Server 8.0.0.8, 8.5.5.0

Testing with PrimeFaces-5.0-SNAPSHOT (we try to always use the newest trunk revision) too.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

06 Dec 2012, 10:57

Please create an issue
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Bardioc
Posts: 85
Joined: 21 Sep 2011, 08:10
Location: Stuttgart, Germany
Contact:

06 Dec 2012, 11:08

I've created an issue under 4972.

Additionally, we partially fixed this by not relying on the System Event, but by modifying CoreRenderer.java in the
following way. It will now create a new widget builder and add it to the context in case none exists there.

Code: Select all

protected WidgetBuilder getWidgetBuilder(FacesContext context) {
    WidgetBuilder wb = (WidgetBuilder) context.getAttributes().get(Constants.WIDGET_BUILDER_ATTR);
    
    if (wb == null)
    {
        wb = new WidgetBuilder();
        
        context.getAttributes().put(Constants.WIDGET_BUILDER_ATTR, wb);
    }
    
    return wb;
}
PrimeFaces 4.0, 5.0-SNAPSHOT
MyFaces 2.0.x (as part of WebSphere Application Server 8)
WebSphere Application Server 8.0.0.8, 8.5.5.0

Testing with PrimeFaces-5.0-SNAPSHOT (we try to always use the newest trunk revision) too.

Bardioc
Posts: 85
Joined: 21 Sep 2011, 08:10
Location: Stuttgart, Germany
Contact:

06 Dec 2012, 11:15

Issue is already rejected: 'NOT PF' ...

Understandable, though not very helpful!
PrimeFaces 4.0, 5.0-SNAPSHOT
MyFaces 2.0.x (as part of WebSphere Application Server 8)
WebSphere Application Server 8.0.0.8, 8.5.5.0

Testing with PrimeFaces-5.0-SNAPSHOT (we try to always use the newest trunk revision) too.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

06 Dec 2012, 11:37

So you need to build your own custom PrimeFaces and maintain after each release? Ouch!

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

06 Dec 2012, 14:19

@Bardioc: Can you explain why it is not a PF issue? I mis this...

Bardioc
Posts: 85
Joined: 21 Sep 2011, 08:10
Location: Stuttgart, Germany
Contact:

06 Dec 2012, 19:05

Well,

I've got in touch with the developers from myfaces-extval. We'll see what they can figure out here. I'm right now trying to create a simple test case. It seems though that myfaces-extval preprocesses the creation of components to integrate client side bean validation. That takes place BEFORE any system event listeners are called. Why? I don't know.

And I've not said it is not Primefaces related, that was Optimus himself :-) He rejected the Issue I've created with 'NOT PF'.

Heiko
PrimeFaces 4.0, 5.0-SNAPSHOT
MyFaces 2.0.x (as part of WebSphere Application Server 8)
WebSphere Application Server 8.0.0.8, 8.5.5.0

Testing with PrimeFaces-5.0-SNAPSHOT (we try to always use the newest trunk revision) too.

ryan.bennett.au
Posts: 4
Joined: 18 Jun 2011, 23:34

05 Feb 2013, 01:52

Similar Issue with Spring Webflow 2.3.x and redirects to subflows. The primefaces RestoreViewPhaseListener is never called because SWF does not consider it a restore event. The following phase listener may help as it will create the request context during the before render response phase if it does not exist. No need to build a custom primefaces CoreRenderer.

Code: Select all

import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.primefaces.context.DefaultRequestContext;
import org.primefaces.util.Constants;

public class RequestContextPhaseListener implements PhaseListener {

	private static final long serialVersionUID = 1832618590862971753L;

	@Override
	public void afterPhase(PhaseEvent event) {

	}

	@Override
	public void beforePhase(PhaseEvent event) {
		FacesContext context = event.getFacesContext();
		if (context.getAttributes().get(Constants.REQUEST_CONTEXT_ATTR) == null) {
			context.getAttributes().put(Constants.REQUEST_CONTEXT_ATTR, new DefaultRequestContext());
		}
	}

	@Override
	public PhaseId getPhaseId() {
		return PhaseId.RENDER_RESPONSE;
	}

}
And add the phase listener using

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
	version="2.0">

	<lifecycle>
		<phase-listener><your.package.>.RequestContextPhaseListener</phase-listener>
	</lifecycle>

</faces-config>

rootkit007
Posts: 37
Joined: 15 Nov 2012, 19:03

06 Feb 2013, 18:18

ryan.bennett.au wrote:Similar Issue with Spring Webflow 2.3.x and redirects to subflows. The primefaces RestoreViewPhaseListener is never called because SWF does not consider it a restore event. The following phase listener may help as it will create the request context during the before render response phase if it does not exist. No need to build a custom primefaces CoreRenderer.
Nice catch! Thanks, you saved my day! :)

Peter

tu_ru
Posts: 1
Joined: 14 Feb 2013, 05:08

15 Feb 2013, 04:18

ryan.bennett.au wrote:Similar Issue with Spring Webflow 2.3.x and redirects to subflows. The primefaces RestoreViewPhaseListener is never called because SWF does not consider it a restore event. The following phase listener may help as it will create the request context during the before render response phase if it does not exist. No need to build a custom primefaces CoreRenderer.
You've just managed to save my day (or rather night) too. Thank you x100. :)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests