You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rick <ri...@arc-mind.com> on 2006/07/04 00:27:49 UTC

Possible Patch for java.lang.NullPointerException in HtmlTree.addToModelListeners

HtmlTree.java (the original not HtmlTree 2) was throwing and exception on
the following line (line 806 for version 1.1.3)

 

    public void addToModelListeners()

    {

        Collection listeners =
getModel(FacesContext.getCurrentInstance()).getTreeModelListeners();
<!-------- NullPointer exception right here..

 

 

The issue was that a TreeModel did not exist yet. This was not an error for
I was conditionally displaying the tree.

 

                        <div jsfc="h:panelGroup"
rendered="#{emergencyContactHandler.tree}">

                        <!-- Tree Table View    ####################
Tree Table View -->

                        <table jsfc="t:tree" id="treeRollup" var="employee"

                                model="#{emergencyContactHandler.treeModel}"

 
value="#{emergencyContactHandler.treeModel}"

                                    rowClasses="oddRow, evenRow"

                                    nodeClass="nodeClass"

                                    columnClasses="col1, col2, col3, col4"

                                    iconNodeOpen="/images/nodrill2.gif"

                                    iconNodeClose="/images/drill2.gif"

 
rendered="#{emergencyContactHandler.tree}">

 

I fixed the problem by adding the following code to restoreState:

 

    public void restoreState(FacesContext context, Object state)

    {

        Object values[] = (Object[]) state;

        super.restoreState(context, values[0]);

.

        if (this.isRendered()){

            addToModelListeners();

        }

    }

 

 

Essentially, I changed restoreState not to call addToModelListeners if we
are not in render mode.

This worked like a charm. 

 

 

I did a search and noticed several other folks were having this problem:

 

java.lang.NullPointerException
 
org.apache.myfaces.custom.tree.HtmlTree.addToModelListeners(HtmlTree.java:80
6)
 
org.apache.myfaces.custom.tree.HtmlTree.restoreState(HtmlTree.java:645)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.ja
va:728)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.ja
va:719)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.ja
va:719)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.ja
va:719)
 
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreComponentState
(JspStateManagerImpl.java:221)
 
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateM
anagerImpl.java:287)
 
org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHan
dlerImpl.java:255)
 
com.sun.facelets.FaceletViewHandler.restoreView(FaceletViewHandler.java:321)
 
org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:14
1)
 
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
 
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.
java:144)

 

 

I am not sure if this patch is general purpose enough but just to let the
next guy know how to fix it I thought I would post it here.


Re: Possible Patch for java.lang.NullPointerException in HtmlTree.addToModelListeners

Posted by Matthias Wessendorf <ma...@apache.org>.
Rick-

thanks for the patch. might be true. anyway, can you bring it up to JIRA?

Would be great!

-Matthias

On 7/3/06, Rick <ri...@arc-mind.com> wrote:
>
>
>
>
> HtmlTree.java (the original not HtmlTree 2) was throwing and exception on
> the following line (line 806 for version 1.1.3)
>
>
>
>     public void addToModelListeners()
>
>     {
>
>         Collection listeners =
> getModel(FacesContext.getCurrentInstance()).getTreeModelListeners();
> <!-------- NullPointer exception right here….
>
>
>
>
>
> The issue was that a TreeModel did not exist yet. This was not an error for
> I was conditionally displaying the tree.
>
>
>
>                         <div jsfc="h:panelGroup"
> rendered="#{emergencyContactHandler.tree}">
>
>                         <!-- Tree Table View    ####################
>                           Tree Table View -->
>
>                         <table jsfc="t:tree" id="treeRollup" var="employee"
>
>
> model="#{emergencyContactHandler.treeModel}"
>
>
> value="#{emergencyContactHandler.treeModel}"
>
>                                     rowClasses="oddRow,
> evenRow"
>
>                                     nodeClass="nodeClass"
>
>                                     columnClasses="col1,
> col2, col3, col4"
>
>
> iconNodeOpen="/images/nodrill2.gif"
>
>
> iconNodeClose="/images/drill2.gif"
>
>
> rendered="#{emergencyContactHandler.tree}">
>
>
>
> I fixed the problem by adding the following code to restoreState:
>
>
>
>     public void restoreState(FacesContext context, Object state)
>
>     {
>
>         Object values[] = (Object[]) state;
>
>         super.restoreState(context, values[0]);
>
> …
>
>         if (this.isRendered()){
>
>             addToModelListeners();
>
>         }
>
>     }
>
>
>
>
>
> Essentially, I changed restoreState not to call addToModelListeners if we
> are not in render mode.
>
> This worked like a charm.
>
>
>
>
>
> I did a search and noticed several other folks were having this problem:
>
>   java.lang.NullPointerException
>
> org.apache.myfaces.custom.tree.HtmlTree.addToModelListeners(HtmlTree.java:806)
>
> org.apache.myfaces.custom.tree.HtmlTree.restoreState(HtmlTree.java:645)
>
> javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:728)
>
> javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:719)
>
> javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:719)
>
> javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:719)
>
> org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreComponentState(JspStateManagerImpl.java:221)
>
> org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:287)
>
> org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:255)
>
> com.sun.facelets.FaceletViewHandler.restoreView(FaceletViewHandler.java:321)
>
> org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:141)
>
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
>
> javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
>
> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
>
>
>
>
>
>
> I am not sure if this patch is general purpose enough but just to let the
> next guy know how to fix it I thought I would post it here.


-- 
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com