2 Replies Latest reply on Apr 24, 2008 6:14 AM by Andrei Markavtsov

    FileUpload: UploadItem.file ambiguity

    Yurii Kartsev Apprentice

      Good afternoon, dear RF developers.

      Faced such a problem while used your example from RF demo for showing uploaded files information. So after some changes my code is this:

      <td style="width:100%">
       <h:panelGrid columns="2" columnClasses="fileupload_top,fileupload_top">
      
       <rich:fileUpload fileUploadListener="#{fuMan.listener}"
       id="upload"
       locale="#{muiMan.locale}"
       uploadData="#{fuMan.fileList}"
       maxFilesQuantity="#{fuMan.maxFiles}"
       immediateUpload="#{fuMan.autoUpload}"
       autoclear="#{fuMan.autoClear}"
       acceptedTypes="#{fuMan.fileTypes}"
       listHeight="#{fuMan.height}" listWidth="#{fuMan.width}">
      
       <a4j:support event="onuploadcomplete" reRender="info" />
      
       <f:facet name="progress">
       <rich:progressBar interval="10000" enabled="true" status="23455667"/>
       </f:facet>
      
       <f:facet name="label">
       <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
       </f:facet>
      
       </rich:fileUpload>
      
       <h:panelGroup>
       <a4j:outputPanel id="info">
      
       <h:outputText value="#{fuMan.fileListSize}"/>
      
       <rich:panel bodyClass="fileupload_info">
       <f:facet name="header">
       <h:outputText value="Uploaded Files Info" />
       </f:facet>
       <h:outputText value="No files currently uploaded"
       rendered="#{fuMan.fileListSize==0}" />
      
       <rich:dataGrid columns="1" value="#{fuMan.fileList}"
       var="uploadItem" rowKeyVar="row">
       <rich:panel>
       <h:panelGrid columns="2">
       <a4j:mediaOutput element="img" mimeType="image/jpeg"
       createContent="#{fuMan.paint}" value="#{row}"
       style="width:100px; height:100px;" />
       <h:panelGrid columns="2">
       <h:outputText value="File Name:" />
       <h:outputText value="#{uploadItem.file.name}" />
       </h:panelGrid>
       </h:panelGrid>
       </rich:panel>
       </rich:dataGrid>
      
       </rich:panel>
       <rich:spacer height="3"/>
       <br />
       <a4j:commandButton action="#{fuMan.clearUploadData}"
       reRender="info, upload" value="Clear Uploaded Data"
       rendered="#{fuMan.fileListSize>0}" />
      
       </a4j:outputPanel>
       </h:panelGroup>
      
       </h:panelGrid>
      </td>


      So, as you see, there is a dataGrid at rich:panel, it has files info with such element: "<h:outputText value="#{uploadItem.file.name}" />". uploadItem - is one item from the list of fuMan.fileList (I have it as new ArrayList() as you have in your demo example on SVN). As I've noticed it's a list of org.richfaces.model.UploadItem, which has two methods:
      /**
       * Return true if file is holding as java.io.File type.
       * If true getFile method should be invoked to get file uploaded.
       * In another case getData method should be invoked to get file's bytes.
       * @return
       */
       public boolean isFile () {
       return (null != file);
       }
      
       /**
       * @return the file
       */
       public File getFile() {
       return file;
       }

      and one member variable "private File file;".

      The ambiguity on my JBoss 4.2.2 is that if I open my view and upload a file - there is an error like "can't find "name" at BOOLEAN uploadItem.file". So it got "boolean file" through isFile method instead of "File file" through getFile method.

      Is it my fault, or the name of isFile() method in org.richfaces.model.UploadItem should be changed?

      Thanks for your answer.

      P.S.: Don't pay any attention for "rich:progressBar" in this example - it's just for testing.