> My understandiing was that when a view is about to be rendered, the
> tags in the page are executed. These tags look for the component in
> the view root and create it if it is not there. This is followed by a
> call to encode that generates the html.
> 

Yep, that's how I understand it too.  Each JSF JSP tag first looks to see if 
the component exists in the component tree and if it doesn't exist, it is 
created and added as a child or facet to the parent.   The tag then invokes 
rendering of each associated component by calling encodeBegin, encodeChildren 
and encodeEnd.


> In my case, on an action method associated with a command button I am
> programmatically adding a set of components to the form. What I did
> was only add some components as children to an existing form.
> Should'nt  the form which was showing its children (that were already
> present in jsp) on the first request, show those that were also added
> dynamically in the second request?
> 

The components added to the from in the JSP using tags are added to the parent 
and rendering invoked as described above.  Components that are added 
dynamically to the form don't have a JSP tag to invoke there rendering.  


You might consider something like the following.  Not sure if it fits into your 
situation but might give you some ideas.  


  private List dynamicComponents = new ArrayList();

  public void encodeBegin(FacesContext context) {
     super.encodeBegin(context);
 
     if (dynamicComponents.size() == 0) {
        UIComponent child = 
context.getApplication().createComponent("javax.faces.outputText");
        //set properties
        dynamicComponents.add(child);
     }

            
  }

   public void encodeEnd(FacesContext context) {
            
           if (!getParent().getRendersChildren() && !getRendersChildren()) { 
              Iterator ci = dynamicComponents.iterator();
              while (ci.hasNext())
                  recursiveRender(context, (UIComponent) ci.next());
           }

           super.encodeEnd(context);
   }



   protected void recursiveRender(UIComponent child,
            FacesContext context) throws IOException {
        
        if (!child.getRendersChildren()) {
            child.encodeBegin(context);
            Iterator ci = child.getChildren().iterator();
            while (ci.hasNext()) {
                UIComponent c = (UIComponent) ci.next();
                c.encodeBegin(context);
                
                if (!c.getRendersChildren())
                    recursiveRender(c, context);
                else
                    c.encodeChildren(context);
                
                c.encodeEnd(context);
                c = null;
            }
            child.encodeEnd(context);
        } else {
            // let the component handle the children
            child.encodeBegin(context);
            child.encodeChildren(context);
            child.encodeEnd(context);
        }
    }    

   
Gary


>  How do I invoke render as mentioned in earlier reply?


Reply via email to