title: Displaying panel using ajax in apache wicket
body: <p>I am learning wicket framework and while working with ajax I tried one example in which I want to display a panel with selected radio button's company name. But while doing this I am getting some error. Here I mentioned all details from my coding:</p>
  
  <p>Test.java</p>
  
  <pre><code>public class Test extends WebPage {
  
  private static final List&lt;String&gt; companies = Arrays.asList(new String[] {"Google","Microsoft","Yahoo"});
  private ArrayList&lt;String&gt; compSelected = new ArrayList&lt;String&gt;();
  private Panel panel;
  public Test(final PageParameters parameters) {
      final RadioChoice&lt;String&gt; companyList = 
                  new RadioChoice&lt;String&gt;("companyNames",new Model(compSelected),companies);
  
      companyList.add(new AjaxFormChoiceComponentUpdatingBehavior() {
  
          @Override
          protected void onUpdate(AjaxRequestTarget target) {
              if("Google".equals(companyList.getModelObject())){
                  panel = new Panel1("panel1","Google");
              }
              else if("Microsoft".equals(companyList.getModelObject())){
                  panel = new Panel1("panel1","Microsoft");
              }
              else{
                  panel = new Panel1("panel1","Yahoo");
              }
              panel.setOutputMarkupId(true);
              target.addComponent(panel);
          }});
      Form&lt;?&gt; form = new Form&lt;Void&gt;("form");
      add(form);
      form.add(companyList);
      form.add(panel);
      this.add(form);
  }
  }
  </code></pre>
  
  <p>Test.html</p>
  
  <pre><code>&lt;form wicket:id="form"&gt;
      &lt;label&gt;&lt;b&gt;Company List:&lt;/b&gt;&lt;/label&gt;&lt;br&gt;
      &lt;span wicket:id="companyNames"&gt;radio button list will goes here&lt;/span&gt;&lt;br&gt;
      &lt;span wicket:id = "panel1" class="panel"&gt;panel goes here&lt;/span&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Panel1.java</p>
  
  <pre><code> @SuppressWarnings("serial")
   public class Panel1 extends Panel{
  
       public Panel1(String id,String cName) {
           super(id);
           add(new Label("msg", "selected company is:"+ cName));
       }
   }
  </code></pre>
  
  <p>Panel1.html</p>
  
  <pre><code>&lt;body&gt;
      &lt;wicket:panel&gt;
          &lt;span wicket:id="msg"&gt;message goes here&lt;/span&gt;
      &lt;/wicket:panel&gt;
  &lt;/body&gt;
  </code></pre>
  
  <blockquote>
    <p>WicketMessage: Can't instantiate page using constructor public demo.wicket.ajax.Test(org.apache.wicket.PageParameters) and argument Root cause:java.lang.IllegalArgumentException: argument child may not be null     at org.apache.wicket.MarkupContainer.add(MarkupContainer.java:131)     at demo.wicket.ajax.Test.(Test.java:46)     at java.lang.reflect.Constructor.newInstance(Unknown Source)     at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:188)     at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:65)     at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:299)     at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:321)     at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)     at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)     at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)     at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)     at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)     at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)     at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468)     at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:301)     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)     at java.lang.Thread.run(Unknown Source)</p>
  </blockquote>
  
  <p>I am not sure what I did wrong here. can someone please help me to figure it out?</p>