super.onFirstShowPage();
final PVerticalPanel panel = new PVerticalPanel();
panel.setSpacing(10);
final PFileUpload fileUpload = new PFileUpload();
fileUpload.setName("my_file");
fileUpload.addSubmitCompleteHandler(new PSubmitCompleteHandler() {
@Override
public void onSubmitComplete() {
PNotificationManager.showTrayNotification("File uploaded, submit file '" + fileUpload.getFileName() + "'");
}
});
fileUpload.addStreamHandler(new StreamHandler() {
@Override
public void onStream(final HttpServletRequest request, final HttpServletResponse response) {
try {
response.setStatus(HttpServletResponse.SC_CREATED);
response.getWriter().print("The file was created successfully.");
response.flushBuffer();
} catch (final IOException e) {
e.printStackTrace();
}
}
});
final PButton submitButton = new PButton("Upload File");
submitButton.showLoadingOnRequest(true);
submitButton.setEnabledOnRequest(false);
submitButton.addClickHandler(new PClickHandler() {
@Override
public void onClick(final PClickEvent event) {
fileUpload.submit();
}
});
panel.add(fileUpload);
panel.add(submitButton);