/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template filePdf, choose Tools | Templates
 * and open the template in the editor.
 */
package form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.apache.struts.validator.ValidatorForm;

/**
 *
 * @author khanhdn1
 */
public class UploadFileForm extends ValidatorForm {

    private FormFile filePdf;

    public FormFile getFilePdf() {
        return filePdf;
    }

    public void setFilePdf(FormFile filePdf) {
        this.filePdf = filePdf;
    }
//
//    @Override
//    public ActionErrors validate(ActionMapping mapping,
//            HttpServletRequest request) {
//
//        ActionErrors errors = new ActionErrors();
//
//        if (getFilePdf().getFileSize() == 0) {
//            errors.add("common.file.err", new ActionMessage("error.filePDF.required"));
//            return errors;
//        }
//
//        //only allow textfile to upload
////        if (!"application/vnd.ms-excel".equals(getFileExcel().getContentType())) {
//        if (!"application/pdf".equals(getFilePdf().getContentType())) {
//            errors.add("common.file.err.ext", new ActionMessage("error.filePDF.contentType"));
//            return errors;
//        }
//
//        //file size cant larger than 10kb
//        System.out.println(getFilePdf().getFileSize());
//        if (getFilePdf().getFileSize() > 10*8388608) { //1MB = 1024 kB = 1024 * 1024 B = 1024 * 1024 * 8 b = 8388608 b
//            errors.add("common.file.err.size",
//                    new ActionMessage("error.filePDF.maxSize"));
//            return errors;
//        }
//
//        return errors;
//    }
}
