• Online Training

    Online Training

    File Upload


    Drag & Drop a InputFile  and change text to Resume
    Drag & Drop a Command Button and change the text to Upload
     





     Write the below code on command Button(upload)& Bind the input file.


    package view;

    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;

    import java.sql.SQLException;

    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;

    import oracle.adf.model.BindingContext;
    import oracle.adf.model.binding.DCIteratorBinding;

    import oracle.binding.BindingContainer;

    import oracle.jbo.Row;
    import oracle.jbo.domain.BlobDomain;

    import org.apache.commons.io.IOUtils;
    import org.apache.myfaces.trinidad.model.UploadedFile;

    public class ResumeBean {
        private UploadedFile resume;
        private String ResumeFileName;
        private String ResumeType;
        public ResumeBean() {
        }

     
        public BindingContainer getBindings(){
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }

        public void setResume(UploadedFile resume) {
            this.resume = resume;
        }

        public UploadedFile getResume() {
            return resume;
        }

        public void setResumeFileName(String ResumeFileName) {
            this.ResumeFileName = ResumeFileName;
        }

        public String getResumeFileName() {
            return ResumeFileName;
        }

      

        public void setResumeType(String ResumeType) {
            this.ResumeType = ResumeType;
        }

        public String getResumeType() {
            return ResumeType;
        }

        public String onAction(FacesContext facesContext, UIComponent uIComponent,Object object) {
            UploadedFile myfile=this.getResume();
               System.out.println("myfile"+myfile);
               DCIteratorBinding iter=( DCIteratorBinding)getBindings().get("StudentBasicInfoView1Iterator");
               String contentType=myfile.getFilename();
               Row row=iter.getCurrentRow();
               row.setAttribute("Resume", createBlobDomain(myfile));
               row.setAttribute("ResumeType",contentType);
              row.setAttribute("ResumeFileName",ResumeFileName);
              return null;
            }
            private BlobDomain  createBlobDomain(UploadedFile resumeField) {
              InputStream in=null;
              BlobDomain blobDomain=null;
              OutputStream out=null;
              try{
                  in=resumeField.getInputStream();
                 blobDomain=new BlobDomain();
                  out=blobDomain.getBinaryOutputStream();
            IOUtils.copy(in,out);
               }
              catch(IOException e) {
               e.printStackTrace();
              }
              catch(SQLException e){
                  e.fillInStackTrace();
              }
              return blobDomain;
           
        }
    }




    Post a Comment