title: How to add anchor in Wicket's setResponsePage()?
body: <p>We need to redirect users that access a certain url to a Wicket page and scroll to a anchor in the page. E.g., the users link directly to <code>http://.../target/url/123</code>. Afterwards, the <code>123</code> id is looked up from database. Subsequently, the user will be redirected to a different page based on if the entity was found or not.</p>
  
  <p>After the entity has been fetched the user should be redirected to <code>http://.../another/url/123#element123</code>. How can we achieve this with Wicket? The page should also be accessible without the anchor, and preferably, the solution should be generic.</p>
  
  <p>One solution I came up with is to override the <code>PageParametersEncoder</code> logic to append <code>#anchor</code> to url when the <code>PageParameters</code> contains an entry named <code>anchor</code>. However, this means that I also need to extend the <code>Url</code> class with my own to append the anchor.</p>
  
  <pre><code>public class ExtendedEncoder extends PageParametersEncoder {
  
      public static final String ANCHOR = "anchor";
  
      @Override
      public Url encodePageParameters(PageParameters pageParameters) {
          Url fromSuper = super.encodePageParameters(pageParameters.remove(ANCHOR));
          return new ExtendedUrl(fromSuper,
                  pageParameters.get(ANCHOR).toOptionalString());
  
      }
  }
  
  public class ExtendedUrl extends Url {
          private String anchor;
  
          private ExtendedUrl(Url url, String anchor) {
              super(url);
              this.anchor = anchor;
          }
  
          @Override
          public String toString(StringMode mode, Charset charset) {
              return super.toString(mode, charset)
                     + anchor == null ? "" : "#" + anchor;
          }
      }
  }
  </code></pre>
  
  <p>Are there any other solutions for the problem?</p>