Hi Ali,

there are some things you made wrong:

First, and this seems to be a popular error: you can't add a component
to another by setting the parent of the child! use
parent.getChildren().add(child) instead.

Than: You dont neet to invoke encoding on every component, just create
then component tree and let jsf do the rest.

Try this :

public void encodeBegin( FacesContext context )
{

   HtmlPanelGrid panelGrid = new HtmlPanelGrid();
   panelGrid.setColumns(2);
   List children = panelGrid.getChildren();

   UIOutput labelName = new UIOutput();
   labelName.setValue("Enter name: ");
   labelName.setId("nameId");
   children.add(labelName);

   UIInput inputName = new UIInput();
   inputName.setId("inputNameId");
   // UIInput needs a valueBinding
   children.add(inputName);

   UIOutput labelAge = new UIOutput();
   labelAge.setValue("Enter age: ");
   labelName.setId("ageId");
   children.add(labelAge);

   UIInput inputAge = new UIInput();
   inputAge.setId("inputAgeId");
   // UIInput needs a valueBinding
   children.add(inputAge);

   this.getChildren.add(panelGrid);

   super.encodeBegin(context);
}


Regards,
  Volker


Ali Raza wrote:
> Greetings again,
> 
> Instead of adding components by rendering the htl myself i am adding
> chilid components and calling their encode methods as following:
> 
> public void encodeBegin( FacesContext context )
>     {
>         try
>         {
>             ResponseWriter writer = context.getResponseWriter();
>             writer.writeComment("********************************* THIS
> IS THE START OF COMPONENT
> **************************************************");
>            
>             HtmlPanelGrid panelGrid = new HtmlPanelGrid();
>             panelGrid.setColumns(2);
>             panelGrid.encodeChildren(context);
>            
>             addComponentBegin(context, "panelGridId", this, panelGrid);
>             addComponentEnd(context, panelGrid);
>            
>             UIOutput labelName = new UIOutput();
>             labelName.setValue("Enter name: ");
>             addComponentBegin(context, "nameId", panelGrid, labelName);
>             addComponentEnd(context, labelName);
>            
>             UIInput inputName = new UIInput();
>             addComponentBegin(context, "inputNameId", panelGrid, inputName);
>             addComponentEnd(context, inputName);
>            
>             UIOutput labelAge = new UIOutput();
>             labelAge.setValue("Enter age: ");
>             addComponentBegin(context, "ageId", panelGrid, labelAge);
>             addComponentEnd(context, labelAge);
>            
>             UIInput inputAge = new UIInput();
>             addComponentBegin(context, "inputAgeId", panelGrid, inputAge); 
>             addComponentEnd(context, inputAge);
>            
>            
>            
>            
>             writer.writeComment("********************************* THIS
> IS THE END OF COMPONENT
> **************************************************");
>         }
>         catch( IOException e )
>         {
> 
>         }
>     } 
>    
>     public static void addComponentBegin( FacesContext context, String
> componentId, UIComponent parentComponent, UIComponent childComponent )
> throws IOException
>     {
>         if( componentId != null )
>         {
>             childComponent.setId( componentId );
>         }
>        
>         childComponent.setParent( parentComponent );
>         childComponent.encodeBegin ( context );
>     }
>    
>     public static void addComponentEnd( FacesContext context,
> UIComponent childComponent ) throws IOException
>     {
>         childComponent.encodeEnd( context );
>     }
> 
> My problem is that the layout of the panel grid (2 columns) that i have
> added is not maintained and all encoded children get rendered ina
> straight line quite like flowlayout in swing. can i use column wise
> layout without having to encode the html myself ???
> 
> Thanx a lot,
> Ali
> 
> -- 
> "A sixteenth century inventor called Wan Hu designed a rocket-propelled
> chair on which he planned to ascend into heaven. He built an open cabin,
> to which he fitted 47 rockets underneath and above, and two kites to
> keep him aloft. Wan Hu disappeared in flame and smoke and was never seen
> again. A crater on the moon is now named after him, so in one sense he
> made it to the heavens after all. This is the first recorded design of
> something approximating to a manned space rocket."
> 
> The Chinese Space Programme.
> From Conception to Future Capabilities.
> Brian Harvey

-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Reply via email to