use of com.liferay.faces.demos.applicant.jsf.jsp.dto.Attachment in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method uploadAttachments.
@SuppressWarnings("unchecked")
public void uploadAttachments(ActionEvent actionEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
File attachmentDir = attachmentManager.getAttachmentDir(facesContext);
if (!attachmentDir.exists()) {
attachmentDir.mkdir();
}
try {
List<UploadedFile> attachments1 = (List<UploadedFile>) attachment1.getValue();
if (attachments1 != null) {
for (UploadedFile uploadedFile : attachments1) {
File copiedFile = new File(attachmentDir, uploadedFile.getName());
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
}
}
List<UploadedFile> attachments2 = (List<UploadedFile>) attachment2.getValue();
if (attachments2 != null) {
for (UploadedFile uploadedFile : attachments2) {
File copiedFile = new File(attachmentDir, uploadedFile.getName());
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
}
}
List<UploadedFile> attachments3 = (List<UploadedFile>) attachment3.getValue();
if (attachments3 != null) {
for (UploadedFile uploadedFile : attachments3) {
File copiedFile = new File(attachmentDir, uploadedFile.getName());
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);
}
applicantView.setFileUploaderRendered(false);
}
use of com.liferay.faces.demos.applicant.jsf.jsp.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.jsf.jsp.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());
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.jsf.jsp.dto.Attachment in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method deleteUploadedFile.
public void deleteUploadedFile(ActionEvent actionEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
int attachmentIndex = Integer.valueOf(requestParameterMap.get("fileId"));
try {
List<Attachment> attachments = applicant.getAttachments();
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);
}
}
Aggregations