5 Replies Latest reply on Oct 15, 2008 7:49 AM by Thomas Kohler

    rich:fileUpload

    Thomas Kohler Newbie

      Hello everybody.

      I have a problem with my rich:fileUpload.

      I use tomcat server 6.0.18, java 6 and richfaces 3.2.1

      on my local server everything works fine, but if i load my content on the tomcat on my webserver the fileupload message says done, but my preview says no files currently uploaded.

      if anybody have a solution for this i will be very lucky.

      my facelets code

      <h:form>
       <h:panelGrid columns="2">
       <rich:fileUpload id="upload"
       acceptedTypes="#{fileUploadBean.acceptedTypes}"
       disabled="#{fileUploadBean.disabled}"
       autoclear="true"
       required="#{fileUploadBean.required}"
       requiredMessage="#{fileUploadBean.requiredMessage}"
       rendered="#{fileUploadBean.rendered}"
       listHeight="#{fileUploadBean.listHeight}"
       listWidth="#{fileUploadBean.listWidth}"
       fileUploadListener="#{fileUploadBean.fileUploadListener}"
       maxFilesQuantity="#{fileUploadBean.maxFilesQuantity}"
       immediateUpload="#{fileUploadBean.immediateUpdate}"
       addControlLabel="#{fileUploadBean.addControlLabel}"
       clearAllControlLabel="#{fileUploadBean.clearAllControlLabel}"
       clearControlLabel="#{fileUploadBean.clearControlLabel}"
       stopEntryControlLabel="#{fileUploadBean.stopEntryControlLabel}"
       uploadControlLabel="#{fileUploadBean.uploadControlLabel}">
       <a4j:support event="onuploadcomplete"
       reRender="info" />
       <f:facet name="progress">
       <rich:progressBar style="height: 10px; width: 250px;">
       </rich:progressBar>
       </f:facet>
       <f:facet name="label">
       <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
       </f:facet>
       </rich:fileUpload>
       <h:panelGroup id="info">
       <rich:panel>
       <f:facet name="header">
       <h:outputText value="Uploaded Files Info" />
       </f:facet>
       <h:outputText value="No files currently uploaded"
       rendered="#{fileUploadBean.size==0}" />
       <rich:dataGrid columns="1" value="#{fileUploadBean.files1}"
       var="file" rowKeyVar="row">
       <rich:panel>
       <h:panelGrid columns="1">
       <a4j:mediaOutput cacheable="false" element="img" mimeType="image/jpeg"
       createContent="#{fileUploadBean.paint}" value="#{row}"
       style="width:100px; "/>
      
       </h:panelGrid>
       </rich:panel>
       </rich:dataGrid>
       </rich:panel>
       <rich:spacer height="3" />
       <br />
       <a4j:commandButton action="#{fileUploadBean.clearUploadData}"
       reRender="info, upload, media"
       value="Fotos entfernen" rendered="#{fileUploadBean.size>0}" />
       </h:panelGroup>
       </h:panelGrid>
      
       </h:form>
      


      and my bean


      public class FileUploadBean {
      
       private boolean disabled;
       private boolean autoclear;
       private boolean rendered;
       private boolean required;
       private String acceptedTypes;
       private String requiredMessage;
       private String listHeight;
       private boolean immediateUpdate;
       private String listWidth;
       private String addControlLabel;
       private String clearAllControlLabel;
       private String clearControlLabel;
       private String stopEntryControlLabel;
       private String uploadControlLabel;
       private List<MyDocument> files1;
       private Integer maxFilesQuantity;
      
       String url = "jdbc:mysql://localhost:3306/";
       String db = "application";
       String driver = "com.mysql.jdbc.Driver";
       String user = "root";
       String pass = "rh7QrVwtu1KOOlda";
       Connection con = null;
       Statement st;
       ResultSet res;
      
       public void loadDriver() throws SQLException {
      
       try {
       Class.forName(driver);
       con = (Connection) DriverManager.getConnection(url + db, user, pass);
       } catch (Exception s) {
       System.out.println("Error in loading driver: " + s);
       }
       }
      
       public FileUploadBean() {
       disabled = false;
       autoclear = false;
       rendered = true;
       required = false;
       immediateUpdate = false;
       acceptedTypes = "jpg, png";
       requiredMessage = "requiredMessage";
       listHeight = "65px";
       listWidth = "350px";
       addControlLabel = "Hinzufügen";
       clearAllControlLabel = "Alle entfernen";
       clearControlLabel = "entfernen";
       stopEntryControlLabel = "Stop";
       uploadControlLabel = "Hochladen";
       maxFilesQuantity = 1;
       files1 = new ArrayList<MyDocument>();
       }
      
       public List<MyDocument> getFiles1() {
       return files1;
       }
      
       public void setFiles1(List<MyDocument> files1) {
       this.files1 = files1;
       }
      
       public Integer getMaxFilesQuantity() {
       return maxFilesQuantity;
       }
      
       public void setMaxFilesQuantity(Integer maxFilesQuantity) {
       this.maxFilesQuantity = maxFilesQuantity;
       }
      
       public void fileUploadListener(UploadEvent event) throws IOException {
       UploadItem item = event.getUploadItem();
       /*
       * if you have createTempFiles context param defined with true -
       * you should use getFile rather than getData in your listener
       */
       if (item != null && item.getData() != null) {
       MyDocument fileData = new MyDocument();
       fileData.setContent(item.getData());
       fileData.setLength(item.getData().length);
       fileData.setName(FilenameUtils.getName(item.getFileName()));
       getFiles1().add(fileData);
       maxFilesQuantity--;
       }
       }
      
       public void paint(OutputStream stream, Object object) throws IOException {
       stream.write(((MyDocument) getFiles1().get((Integer) object)).getContent());
       }
      
       public Integer getSize() {
       return getFiles1().size();
       }
      
       public String clearUploadData() {
       files1.clear();
       maxFilesQuantity = 1;
       return null;
       }
      
      //getters an setters
      


      thank you all