Tree.processUpdates Fails in 2.2 -- solved

UI Components for JSF
Post Reply
Alan
Posts: 102
Joined: 25 Oct 2010, 04:45

15 Feb 2011, 03:09

This issue started happening to me when I switched to 2.2 -- it didn't happen in 2.2 RC 2. Unfortunately I started using p:inputText which isn't in RC2 so I would like to find a workaround for 2.2.

The p:tree element below is in my Faclets template, so it shows up on every view in my application. The nodeSelectListener will execute an ExternalContext.redirect to a URL depending on what node was selected. This has always worked very well and still works.

The NullPointerException happens now when I do some other navigation by selecting some regular link on the page.

In the page I have:

Code: Select all

                    <p:tree id="navTreeShelf" 
                            value="#{navigation.navigationTree}"
                            dynamic="true"
                            var="node"
                            selectionMode="single"
                            nodeSelectListener="#{navigation.onNodeSelect}"
                            rendered="#{!appBean.dataBaseEmpty}" 
                            style="font-size:75%"
                            >
                        <p:treeNode>
                            <h:outputText value="#{navigation.nodeDisplay(node)}" />
                        </p:treeNode>
                    </p:tree>

Code: Select all

java.lang.NullPointerException
	at org.primefaces.component.tree.Tree.processUpdates(Tree.java:318)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
	at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
	at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231)
	at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
I downloaded the source but I am not sure what the code is doing enough that I can figure out how to keep this from happening. Any advice?

(Thanks in advance as always).
Last edited by Alan on 16 Feb 2011, 03:23, edited 1 time in total.
Netbeans 7.1, GlassFish 3.1.1, MacOS X 10.6.8, Safari, Firefox

Alan
Posts: 102
Joined: 25 Oct 2010, 04:45

16 Feb 2011, 01:11

This issue shows up in 2.2.1 as well.

The code up to line 318 (the source of the NPE) is as follows:

Code: Select all

public void processUpdates(FacesContext context) {
		super.processUpdates(context);
        
        String selectionMode = this.getSelectionMode();

        if(selectionMode != null) {

            Object selection = this.getLocalSelectedNodes();
            Object previousSelection = this.getValueExpression("selection").getValue(context.getELContext());
Setting a breakpoint, I can see that the local variable "selection" is null, and it appears that the getValueExpression("selection") returns a null, causing the call to getValue() to throw the NPE. At least I think that is what is happening. Any advice?
Netbeans 7.1, GlassFish 3.1.1, MacOS X 10.6.8, Safari, Firefox

Alan
Posts: 102
Joined: 25 Oct 2010, 04:45

16 Feb 2011, 03:26

As it turns out, the new code for Tree requires that the p:tree element have a selection attribute.

My nodeSelectListener did not need this attribute because it was getting the selected node from its NodeSelectEvent parameter. In PrimeFaces prior to 2.2, the selection attribute could be omitted so I hadn't seen this before.

Hope this helps someone...
Netbeans 7.1, GlassFish 3.1.1, MacOS X 10.6.8, Safari, Firefox

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests