The solution I ended up finding for this was to add this code to my constructor:

        boolean isInitialRequest = getFacesContext().getRenderResponse();
        if (isInitialRequest)
        {
            addChildrenAndFacets();
        }


On 5/6/05, Mike Kienenberger <[EMAIL PROTECTED]> wrote:
> I've built a custom HtmlDataTable/UIColumns composite component.
> 
> My problem is that I'm initializing the programmically-created UIData
> facet/children in my constructor, and this appears to be the wrong
> approach.
> 
> This works fine on the initial display of the component.  However,
> after the component is restored, it then has two copies of each
> facet/child, one from the constructor, and one from the restoreState.
>  This causes processRestoreState to die horribly.
> 
> What's the correct way to set up children/facets?  Or to put it
> another way, what's the correct way to detect that the component is
> being constructed in an "initial request?"
> 
> The Kito Mann "JSF in Action" book has this being done in the
> constructor for UIHeadlineViewer, but while I love the layout and
> concepts in this book, the example code seems as if it's never been
> executed.
> 
> I noticed that HtmlTree has this code in encodeBegin, and I'm
> wondering if this is the recommended way to detect the initial request
> state or just some integrity-checking.
> 
> Thanks!
> -Mike
> 
>     public void encodeBegin(FacesContext context) throws IOException
>     {
>         /// [...]
> 
>         if (!itemStatesRestored)
>         {
>             UIViewRoot previousRoot = (UIViewRoot)
> context.getExternalContext().getRequestMap().get(PREVIOUS_VIEW_ROOT);
>             if (previousRoot != null)
>             {
>                 restoreItemStates(context, previousRoot);
>             } else
>             {
>                 //no previous root, means no decode was done
>                 //--> a new request
>             }
>         }
> 
>         super.encodeBegin(context);
>     }
>

Reply via email to