title: Wicket - Display a PDF in a new window
body: <p>With Wicket 1.5, I need to display a PDF file in a new Window. To do that, I extend ByteArrayResource. The problem is that there is only two options in content disposition: attachment and inline.</p>
  
  <p>The first one download the file, and it's too long for my users to do that when they want to just consult the file.
  The second one open the file in the same window and the users want a new window to continue to work with the document opened.</p>
  
  <p>Here is my ByteArrayResource code:</p>
  
  <pre><code>public class FileArchiveRessource extends ByteArrayResource {
  
      private final String genericName;
      private final Locale locale;
  
      public FileArchiveRessource(String genericName, Locale locale) {
          super("application/pdf");
          this.genericName = genericName;
          this.locale = locale;
          this.contentType = "application/pdf";
      }
  
      @Override
      protected byte[] getData(IResource.Attributes attributes) {
          try {
              String name = genericName.replaceAll("[{][$][}]", locale.getLanguage().toUpperCase());
              return IOUtils.toByteArray(this.getClass().getResourceAsStream(name));
          } catch (IOException ex) {
              return new byte[0];
          }
      }
  
      @Override
      protected void configureResponse(ResourceResponse response, Attributes attributes) {
          super.configureResponse(response, attributes);
          response.setContentDisposition(ContentDisposition.INLINE);
      }
  }
  </code></pre>
  
  <p>In this implementation, {$} in the name is replaced by the language of the user.</p>
  
  <p>How the resource is instanciated:</p>
  
  <pre><code>final Locale locale = getLocale();
  final String name = "document-{$}.pdf".replaceAll("[{][$][}]", locale.getLanguage().toUpperCase());
  ResourceLink button = new ResourceLink("list.openbutton", new ResourceReference(name) {
      @Override
      public IResource getResource() {
          return new FileArchiveRessource(name, locale);
      }
  });
  
  add(button);
  </code></pre>
  
  <p>And here is an example of a open button of my resource:</p>
  
  <pre><code>&lt;input wicket:id="list.openbutton"
         type="submit"
         class="button openbutton"
         value="Open" title="Open resource" /&gt;
  </code></pre>
  
  <p>Any suggestion?</p>
  
  <p>Precision:
  I really need a new separate window, not a new tab.</p>