示例#1
0
  /** Unit test for create(clazz). */
  @SuppressWarnings({"nls", "rawtypes", "unchecked"})
  @Test
  public void testAction() {
    RequestCycle rc = RequestCycle.get();
    Bo2WicketRequestCycle.beginRequest(rc);

    BeanWith3Fields[] beans = {
      new BeanWith3Fields("one", 1, 1.0), new BeanWith3Fields("two", 2, 2.0)
    };
    List<BeanWith3Fields> list = Arrays.asList(beans);
    String[] properties = {"field1", "field2"};
    String[] labels = {"Field 1", "Field 2"};
    String filename = "TestCsvFile.csv";

    List2CsvActionClient client = Mockito.mock(List2CsvActionClient.class);
    Mockito.when(client.getList()).thenReturn((List) list);
    Mockito.when(client.getPropertiesToExport()).thenReturn(properties);
    Mockito.when(client.getColumnLabels()).thenReturn(labels);
    Mockito.when(client.getFileName()).thenReturn(filename);

    List2CsvAction action = new List2CsvAction(client);

    action.execute();
    IRequestHandler target = rc.getRequestHandlerScheduledAfterCurrent();
    Assert.assertTrue(target instanceof ResourceStreamRequestHandler);
    ResourceStreamRequestHandler rt = (ResourceStreamRequestHandler) target;
    Assert.assertEquals(rt.getFileName(), client.getFileName());
    Bo2WicketRequestCycle.endRequest(rc);
  }
 public void onRequest() {
   ResourceStreamRequestHandler handler =
       new ResourceStreamRequestHandler(getResourceStream(), getFileName()) {
         @Override
         public void respond(IRequestCycle requestCycle) {
           super.respond(requestCycle);
           model.setObject(Boolean.FALSE);
         }
       };
   handler.setContentDisposition(ContentDisposition.ATTACHMENT);
   getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
 }
示例#3
0
  @Override
  public void onRequest() {
    ResourceStreamRequestHandler handler =
        new ResourceStreamRequestHandler(
            new AbstractResourceStreamWriter() {
              private static final long serialVersionUID = -4234161758492585332L;

              @Override
              public void write(OutputStream output) throws IOException {
                escrever(output);
              }
            },
            getNomeArquivo());
    handler.setFileName(getNomeArquivo());
    handler.setContentDisposition(ContentDisposition.ATTACHMENT);
    if (antiCache) {
      handler.setCacheDuration(Duration.NONE);
    }
    getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
  }