0 Replies Latest reply on Sep 22, 2010 4:52 PM by shwetank sharma

    File uploading  Problem with modelPanel

    shwetank sharma Newbie

      Hi ,
          I am tring to upload a file than File Uploading successfully but ModelPanel not hidding .


          Code is there




      <a:outputPanel id="commonPanel">
                     <rich:modalPanel id="commonMp" styleClass="modalPanel" top="10"
                          keepVisualState="#{manageMasterMaintenanceJob.showOverlay}"
                          autosized="true" minWidth="600" minHeight="100"
                          style="background-image: url('../img/overlayBg.png');background-repeat: repeat;background-color: transparent;"
                          shadowDepth="#{messages.valShadowDepth}"
                          headerClass="modalPanel-header" controlsClass="modalPanel-controls">
                          <f:facet name="header">
                               <h:outputText value="#{manageMasterMaintenanceJob.modelPanelHead}" />
                          </f:facet>
                          <f:facet name="controls">
                               <a:form ajaxSubmit="true" id="closeLayer">
                                    <a:commandLink action="#{manageMasterMaintenanceJob.closeLayer}"
                                         oncomplete="Richfaces.hideModalPanel('commonMp')">
                                         <h:graphicImage value="/img/closeButton.png" alt="X" border="0" />
                                    </a:commandLink>
                               </a:form>
                          </f:facet>
      
      <h:panelGrid styleClass="modalPanel-panelGrid">
                               <h:message styleClass="message" for="commonPanel"
                                    style="color:red;" />
                               <h:form enctype="multipart/form-data">
      
      
      <h:panelGrid columns="1" columnClasses="name"
                                         rendered="#{manageMasterMaintenanceJob.formToLoad=='uploadHowToFileForm'}"
                                         styleClass="panelGrid">
                                         <s:div styleClass="modalPanel-panelGrid-container-div">
      
                                              <h:panelGrid styleClass="modalPanel-panelGrid">
      
                                                   <h:panelGrid columns="1" border="0"
                                                        columnClasses="formLabel,formValue" rowClasses="formLabel">
                                                        <s:decorate id="UploadedFileName"
                                                             rendered="#{manageMasterMaintenanceJob.uploadedFile!= null}"
                                                             template="../layout/edit.xhtml">
                                                             <ui:define name="label">#{messages.lblUploadedHowToFile}: </ui:define>
                                                             <h:outputText
                                                                  value="#{manageMasterMaintenanceJob.uploadedFile}"
                                                                  rendered="#{manageMasterMaintenanceJob.uploadedFile!= null}" />
                                                        </s:decorate>
      
                                                        <s:decorate id="UploadFileName"
                                                             template="../layout/edit.xhtml">
                                                             <ui:define name="label">#{messages.lblUploadHowToFile}</ui:define>
                                                             <s:fileUpload id="howtofile"
                                                                  data="#{manageMasterMaintenanceJob.fileData}"
                                                                  fileName="#{manageMasterMaintenanceJob.fileName}"
                                                                  style="height:20px;" required="true"
                                                                  requiredMessage="#{messages['message.required.maintenanceJobType.uploadHowToFile']}" />
                                                        </s:decorate>
      
                                                        <h:commandButton value="#{messages.btnUpload}"
                                                             action="#{manageMasterMaintenanceJob.persistHowToFile}" >
                                                             <a:support event="onclick" reRender="commonPanel" data="#{facesContext.maximumSeverity.ordinal == 0}"
                                                             oncomplete="if(data == true) Richfaces.hideModalPanel('commonMp');" 
                                                             
                                                              action="#{manageMasterMaintenanceJob.closeLayer}"
                                                                   />
                                                        </h:commandButton>
                                                   </h:panelGrid>
                                              </h:panelGrid>
                                         </s:div>
                                    </h:panelGrid>
      
      </h:form>
                          </h:panelGrid>
                     </rich:modalPanel>
      
                </a:outputPanel>




      JAVA Code





      @Begin(join = true)
           public void persistHowToFile() {
                log.info("Entering persistHowToFile() method");
                log.info("File Name: " + fileName);
                log.info("master job id: " + mJobId);
                this.masterJob = entityManager.find(MasterJob.class, mJobId);
                try {
                     if (fileName.equals("") || fileData.length == 0) {
                          //facesMessages.addFromResourceBundle("message.masterJobFile.select.file");
                          
                          log.info("enter to check null file name");
                     //     facesMessages.addToControlFromResourceBundle("commonPanel", "message.required.masterMaintenanceJob.uploadHowToFile");
                          facesMessages.addFromResourceBundle(javax.faces.application.FacesMessage.SEVERITY_ERROR, 
                          "message.required.masterMaintenanceJob.uploadHowToFile"); 
                          //showOverlay = true;
                     }
                     else {
                          Integer extPos;
                          extPos = fileName.lastIndexOf(".");
                          String startName = fileName.substring(0, extPos);
                          String fileType = fileName.substring(extPos);
                          log.info("before validating fileType Type: " + fileType);
                          /*
                           * if ((fileType.equalsIgnoreCase(".jpg")) ||
                           * (fileType.equalsIgnoreCase(".png")) || (fileType.equals(".bmp")) ||
                           * (fileType.equals(".jpeg"))) {
                           */
                          log.info("After validating fileType");
                          StringBuffer dirName = new StringBuffer("");
                          SeamResourceBundle sRB = new SeamResourceBundle();
                          // getting path from resource bundle
                          dirName.append(sRB.getString("uploaded_files"));
                          // dirName.append("masterJobFile");
                          dirName.append(startName);
                          dirName.append(masterJob.getImasterJobId());
                          dirName.append(fileType);
                          File saveTo = new File(dirName.toString());
      
                          log.info("before writing");
                          log.info("File Data : " + fileData);
                          // Writing file
                          FileOutputStream writer = new FileOutputStream(saveTo);
                          writer.write(fileData);
                          // new file name
                          // fileName = "companyLogo" + masterJob.getImasterJobId() + fileType;
                          // setting companyLogo
                          masterJob.setStrHowToLocation(fileName);
                          log.info("#########added file name : " + masterJob.getStrHowToLocation());
      
                          // peristing company logo
                          entityManager.merge(masterJob);
                          facesMessages.addFromResourceBundle(javax.faces.application.FacesMessage.SEVERITY_INFO, 
                          "message.add.masterJob.uploadHowToFile.successful");
                          
                          showOverlay = false;
                          /*
                           * } else { facesMessages
                           * .addFromResourceBundle("message.companyLogo.wrong.extention");
                           * log.info("extention validation failed"); }
                           */
                     }
                }
                catch (Exception e) {
                     log.info("Exception===" + e.getMessage());
                     ctx.setRollbackOnly();
      
                }
           }






      public void closeLayer() {
                log.info("Entering closeLayer() method");
                showOverlay = false;
           }





      Regards,


      Ambrish