title: Wicket: AjaxRequestTarget vs onModelChanged
body: <p>I'm working on a code in a wicket project, where the original devs used the <code>onModelChanged()</code> method quite a lot in Ajax request handling methods. I, for one, however am not a strong believer of this implementation.</p>
  
  <p>In fact, I can't think of any examples, where calling the <code>target.add(...)</code> is inferior to calling the onModelChanged method.</p>
  
  <p>Am I missing some key concepts here?</p>
  
  <p>Example:</p>
  
  <pre><code>public MyComponent extends Panel {
  
      public MyComponent(String id, Component... componentsToRefresh) {
  
          add(new AjaxLink&lt;Void&gt;("someId") {
              @Override
              public void onClick(AjaxRequestTarget target) {
                  // some logic with model change
  
                  for(Component c: componentsToRefresh) {
                      c.modelChanged();
                  }
  
                  target.add(componentsToRefresh);
              }
          };
      }
  }
  </code></pre>
  
  <p>Now, there are a couple of things I don't agree with, the very first is the componentsToRefresh parameter, the second is (as the question suggests), the fact that we called <code>c.modelChanged()</code> on all components in that array. My guess would be that it is completely un necessary and instead of a parameter in the constructor, one should just write an empty function in <code>MyComponent</code> and override it, and put the necessary components in there when needed.</p>