public String buttonRefresh_action() {
return null;
}
public String buttonUpload_action() {
UploadedFile uploadedFile = fileUpload.getUploadedFile();
DocumentFileManager documentFileManager =
new DocumentFileManager(uploadedFile.getOriginalName(),
getClientPath());
String justFileName = documentFileManager.getFileName();
String uploadedFileType = uploadedFile.getContentType();
//default name of document
String doc ;
if (title.getText() == null ||
((String) title.getText()).trim().length() == 0) {
doc = documentFileManager.getTitle();
} else {
doc = ((String) title.getText()).trim();
}
try {
File file = new File(documentFileManager
.getFilenameOnServer(getServerPath()));
if (!documentFileManager.isMatchingClientPath()) {
uploadedFile.write(file);
info("Uploaded file originally named '" +
uploadedFile.getOriginalName() + "' writed to " +
documentFileManager.getFilenameOnServer(getServerPath()));
}
// Persist the doc ref
this.document.setContact(getContact());
this.document.setDocumentLink(justFileName);
this.document.setTitle(doc);
this.document.setDocumentType(uploadedFileType);
this.document = new DocumentController().update(this.document);
getContact().getDocumentLinks().add(this.document);
new ContactController().update(
getContact());
title.setText("");
} catch (Exception ex) {
error("Cannot upload file: " + uploadedFile.getOriginalName() + " to " +
documentFileManager.getFilenameOnServer(getServerPath()) +
"(" + ex.getClass().getName() + " msg: " + ex.getMessage() + ").");
}
list.refreshListContact();