title: Help on JSF 2.0 Custom Components and Primefaces
body: <p>I have a requirement to create a panel dynamically using jsf 2.0 custom components. The controls within the panel will be dynamically read from an xml and rendered on the selection of the corresponding object (Eg : If Person is selected, I should render a panel which will have controls related to person like : Person age field(inputtext), Person DOB(calendar) and so on). </p>
  
  <p>I am trying to render it from the component class which extends UIComponentBase. </p>
  
  <pre><code>ResponseWriter writer = Util.getResponseWriter(context);
  //start the &lt;table&gt; tag
  writer.startElement(Constants.STR_TABLE, this);
  
  //start the &lt;tr&gt; tag
  writer.startElement(Constants.STR_TR, this);
  
  //start the &lt;td&gt; tag
  writer.startElement(Constants.STR_TD, this);
  
  //encode the button 1 component inside this &lt;td&gt;
  encodeAllComponent(context, getMyPrimePanel());
  
  // end the &lt;td&gt; tag
  writer.endElement(Constants.STR_TD);
  
  //end the &lt;tr&gt; tag
  writer.endElement(Constants.STR_TR);
  
  
  //end the &lt;table&gt; tag
  writer.endElement(Constants.STR_TABLE);
  
    //private variable to render a panel
    private Panel myPrimePanel;
  
    /**
    * @return the myPrimePanel
    */
    public Panel getMyPrimePanel() {
          System.out.println("inside the panel get method------");
          if (myPrimePanel.getChildCount() &lt;= 1) {
                System.out.println("inside the panel creation function");
                InputText input = new InputText();
                myPrimePanel.getChildren().add(input);
  
          }
          System.out.println("inside the panel get method-------------");
          return myPrimePanel;
    }
  
    /**
    * @param myPrimePanel the myPrimePanel to set
    */
    public void setMyPrimePanel(Panel myPrimePanel) {
          System.out.println("inside the panel get method-------------");
          //initialize the button 1 component
          this.myPrimePanel = myPrimePanel;
    }
  </code></pre>
  
  <p>I have done this way. But I am getting a null pointer exception. How can the panel with the defined controls be rendered dynamically? </p>
  
  <p>This is what I'm getting - </p>
  
  <p>====Will Start Rendering==== 
  inside the panel get method------ 
  Sep 7, 2011 10:01:42 AM com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit 
  SEVERE: java.lang.NullPointerException</p>