title: Wicket component won't refresh via AJAX
body: <p>I have a Wicket page with some components that should be updated via AJAX. I have the following AjaxBehavior:</p>
  
  <pre><code>private class MyAjaxBehavior extends AbstractDefaultAjaxBehavior {
  
          @Override
          public void renderHead(IHeaderResponse response) {
              super.renderHead(response);
              response.renderOnLoadJavascript("wicketAjaxPost(\"" + getCallbackUrl() + "\")");
          }
  
          @Override
          public void onConfigure(Component component) {
              firstComponent.setOutputMarkupId(true);
              secondComponent.setOutputMarkupId(true);
          }
  
          @Override
          protected void respond(AjaxRequestTarget target) {
              firstComponent.replaceWith(createFirstComponent());
              target.addComponent(firstComponent);
  
              secondComponent.replaceWith(createSecondComponent());
              target.addComponent(secondComponent);
          }
      }
  </code></pre>
  
  <p>And I have a component hierarchy like this:</p>
  
  <pre><code>Page
  - fragment1
    - fragment1-1
      - firstComponent
  - secondComponent
  </code></pre>
  
  <p>The problem is <code>firstComponent</code> never refreshed after AJAX callback. <code>secondComponent</code> is updated correctly. I tried to move <code>firstComponent</code> to <code>frament1-1</code> (just  experiment) and it worked! I tried to use some extra fragments to wrap <code>firstComponent</code> but it didn't help. </p>
  
  <p>I tried to debug Wicket's <code>AjaxRequestTarget.respondComponent()</code>. There is the following code:</p>
  
  <pre><code>        // Initialize temporary variables
          final Page page = component.findParent(Page.class);
          if (page == null)
          {
              // dont throw an exception but just ignore this component, somehow
              // it got
              // removed from the page.
              // throw new IllegalStateException(
              // "Ajax request attempted on a component that is not associated
              // with a Page");
              LOG.debug("component: " + component + " with markupid: " + markupId +
                  " not rendered because it was already removed from page");
              return;
          }
  </code></pre>
  
  <p><code>page</code> is null here for both <code>firstComponent</code> and <code>secondComponent</code> but the second one somehow gets re-rendered.</p>
  
  <p>Any ideas why <code>firstComponent</code> is not re-rendered? Where should I dig? I use Wicket 1.4.22.</p>
  
  <p><strong>UPD</strong></p>
  
  <p>I tried to add the new component to <code>target</code> and not the old one. It creates the new component on the page but doesn't refresh the old one. So I have two components on the page instead of one. Also it breaks HTML markup structure for some reason. Like this:</p>
  
  <pre><code>&lt;div&gt;
      &lt;div id="generated"&gt;new component is added here&lt;/div&gt;
      &lt;table&gt;
          ...
          &lt;tr&gt;old component&lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My wicket markup for <code>firstComponent</code> looks like this:</p>
  
  <pre><code>&lt;div&gt;
      &lt;table class="summary" style="width: 100%"&gt;
          &lt;tr&gt;
              &lt;div wicket:id="firstComponent" /&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  
  ...
  
  &lt;wicket:fragment wicket:id="firstComponentFragment"&gt;
      &lt;th&gt;title&lt;/th&gt;
      &lt;td&gt;&lt;span wicket:id="someText"&gt;&lt;/span&gt;&lt;/td&gt;
  &lt;/wicket:fragment&gt;
  </code></pre>
  
  <p>So you can see the new component is added outside the table.</p>