use of com.liferay.faces.demos.applicant.richfaces.facelets.dto.Attachment in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method deleteUploadedFile.
public void deleteUploadedFile(ActionEvent actionEvent) {
try {
List<Attachment> attachments = applicant.getAttachments();
int attachmentIndex = applicantView.getAttachmentIndex();
Attachment attachmentToDelete = null;
for (Attachment attachment : attachments) {
if (attachment.getIndex() == attachmentIndex) {
attachmentToDelete = attachment;
break;
}
}
if (attachmentToDelete != null) {
attachmentToDelete.getFile().delete();
attachments.remove(attachmentToDelete);
logger.debug("Deleted file=[{0}]", attachmentToDelete.getName());
}
} catch (Exception e) {
logger.error(e);
}
}
use of com.liferay.faces.demos.applicant.richfaces.facelets.dto.Attachment in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method submit.
public String submit() {
if (logger.isDebugEnabled()) {
logger.debug("firstName=" + applicant.getFirstName());
logger.debug("lastName=" + applicant.getLastName());
logger.debug("emailAddress=" + applicant.getEmailAddress());
logger.debug("phoneNumber=" + applicant.getPhoneNumber());
logger.debug("dateOfBirth=" + applicant.getDateOfBirth());
logger.debug("city=" + applicant.getCity());
logger.debug("provinceId=" + applicant.getProvinceId());
logger.debug("postalCode=" + applicant.getPostalCode());
logger.debug("comments=" + applicant.getComments());
List<Attachment> attachments = applicant.getAttachments();
for (Attachment attachment : attachments) {
logger.debug("attachment=[{0}]", attachment.getName());
}
}
// Delete the uploaded files.
try {
List<Attachment> attachments = applicant.getAttachments();
for (Attachment attachment : attachments) {
attachment.getFile().delete();
logger.debug("Deleted file=[{0}]", attachment.getName());
}
// Store the applicant's first name in JSF 2 Flash Scope so that it can be picked up
// for use inside of confirmation.xhtml
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.getExternalContext().getFlash().put("firstName", applicant.getFirstName());
applicant.clearProperties();
return "success";
} catch (Exception e) {
logger.error(e.getMessage(), e);
FacesContextHelperUtil.addGlobalUnexpectedErrorMessage();
return "failure";
}
}
use of com.liferay.faces.demos.applicant.richfaces.facelets.dto.Attachment in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method postConstruct.
@PostConstruct
public void postConstruct() {
applicant = new Applicant();
FacesContext facesContext = FacesContext.getCurrentInstance();
File attachmentDir = attachmentManager.getAttachmentDir(facesContext);
List<Attachment> attachments = attachmentManager.getAttachments(attachmentDir);
applicant.setAttachments(attachments);
}
use of com.liferay.faces.demos.applicant.richfaces.facelets.dto.Attachment in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method handleFileUpload.
public void handleFileUpload(FileUploadEvent fileUploadEvent) throws Exception {
org.richfaces.model.UploadedFile uploadedFile = fileUploadEvent.getUploadedFile();
FacesContext facesContext = FacesContext.getCurrentInstance();
File attachmentDir = attachmentManager.getAttachmentDir(facesContext);
if (!attachmentDir.exists()) {
attachmentDir.mkdir();
}
File copiedFile = new File(attachmentDir, uploadedFile.getName());
try {
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
List<Attachment> attachments = attachmentManager.getAttachments(attachmentDir);
applicant.setAttachments(attachments);
} catch (IOException e) {
logger.error(e);
}
}
Aggregations