3 Replies Latest reply on Jun 26, 2008 4:09 AM by Pavel Perepelitsa

    inputText not Updating in Backing Bean

    Anthony Mattas Newbie

      I'm trying to upload a file and pull data in from a description field when the listener processes the request. Here is the applicable code, however the description always ends up being null in the database.

       <h:form enctype="multipart/form-data" id="upload">
       <h:panelGrid columns="2">
       <h:outputText value="Description: " id="description" />
       <h:inputText value="#{OrderView.uploadDescription}" id="uploadDescription" immediate="true" >
       <a4j:support event="onkeyup" reRender="upload" />
       </h:inputText>
       </h:panelGrid>
       <rich:fileUpload id="upload"
       immediateUpload="true" fileUploadListener="#{OrderView.addUpload}"
       disabled="#{fn:length(OrderView.uploadDescription) lt 10}">
       </rich:fileUpload>
       <span id="submitbutton"><h:commandButton value="Done"
       action="success" styleClass="button" /> </span>
       </h:form>
      


       public void addUpload(UploadEvent event) {
       if (event == null) { _logger.warning("null upload event"); }
       UploadItem uploadItem = event.getUploadItem();
       FileInputStream inputStream;
       FileOutputStream outputStream;
       FacesContext facesContext = FacesContext.getCurrentInstance();
       ExternalContext externalContext = facesContext.getExternalContext();
       String username = externalContext.getUserPrincipal().getName();
       String filename = Long.toString(new Date().getTime());
       String extension = fileExtension(uploadItem.getFileName());
       String uploadLocation = this.getUploadParent() + '/' + this.getUploadSuffix() + '/';
       File outputDir = new File(uploadLocation);
       if (!outputDir.exists()) outputDir.mkdirs();
       try {
       System.out.println(uploadLocation + filename + extension);
       outputStream = new FileOutputStream(uploadLocation + filename + extension);
       if (uploadItem.isFile()) {
       inputStream = new FileInputStream(uploadItem.getFile());
       outputStream.getChannel().transferFrom(inputStream.getChannel(), 0, inputStream.getChannel().size());
       inputStream.close();
       } else
       outputStream.write(uploadItem.getData());
       outputStream.close();
       setters.addFile(this.getId(), filename+extension, this.getUploadDescription(), username);
       } catch (FileNotFoundException e) {
       _logger.severe("input file not found");
       } catch (IOException e) {
       _logger.severe("can't write output file");
       } catch (UnknownUserException e) {
       _logger.severe("upload user does not exist");
       } catch (UnknownOrderException e) {
       _logger.info("upload order does not exist");
       }
      
      
       }