1 Reply Latest reply on Jun 3, 2009 8:47 AM by John Ament

    Richfaces FIle Upload +WebBeans +Jboss AS 5.1 = no go?

    John Ament Master

      This one's irking me. I've gotten examples like this working before in seam, not sure why it's not working w/ just webbeans.

      I have a facelet defined like this:

       <ui:composition template="template.xhtml">
       <ui:define name="pageTitle">Webstore Image Uploader</ui:define>
       <ui:define name="pageHeader">Image Uploader</ui:define>
       <ui:define name="body">
       <h:form>
       <h:outputText value="Currently logged in as: #{login.name}" /><br />
       <h:selectBooleanCheckbox value="#{uploader.override}" />Override Existing Files<br />
       <rich:dataList var="result" value="#{uploader.messages}" id="status">
       <h:outputText value="#{result}" />
       </rich:dataList>
       <rich:fileUpload acceptedTypes="tif" allowFlash="true" maxFilesQuantity="100"
       fileUploadListener="#{uploader.onUpload}">
       <a4j:support event="onuploadcomplete" reRender="status" />
       </rich:fileUpload>
       </h:form>
       </ui:define>
       </ui:composition>
      


      And a bean defined like this:

      @Named("uploader") @SessionScoped
      public class FileUploadListener implements java.io.Serializable{
       //@Current ImageDAO imageDAO;
       @Current LoginBean login;
       private static final Logger logger = Logger.getLogger(FileUploadListener.class);
       private List<String> messages = new ArrayList<String>();
       private boolean override = true;
       public List<String> getMessages() {
       if(messages.size() == 0){
       messages.add("Welcome message.");
       }
       return messages;
       }
       public void setMessages(List<String> messages) {
       this.messages = messages;
       }
       public boolean isOverride() {
       return override;
       }
       public void setOverride(boolean override) {
       this.override = override;
       }
       public void onUpload(UploadEvent e) {
       logger.error("Calling on upload: "+e.getUploadItems().size());
       messages = new ArrayList<String>();
       //List<UploadItem> items = e.getUploadItems();
       //for(UploadItem item : items) onItem(item);
       onItem(e.getUploadItem());
       if(messages.isEmpty()) {
       if(logger.isDebugEnabled())
       logger.debug("No errors during upload.");
       messages.add("All files uploaded successfully");
       }
       }
       private void onItem(UploadItem item) {
       File src = item.getFile();
       String fileName = item.getFileName();
       int size = item.getFileSize();
       //boolean existsFile = PathUtils.fileExists(fileName);
       boolean existsDB = false;
       boolean exists = PathUtils.fileExists(fileName) && existsDB;
       if(!exists || (exists && isOverride())) {
       File img = PathUtils.locateFile(fileName);
       try {
       img.createNewFile();
       } catch (IOException e) {
       logger.error("Problem creating new image: "+fileName,e);
       }
       src.renameTo(img);
       } else {
       messages.add("Overrides disabled and image found: "+fileName);
       }
      
       }
      


      It looks like the rich file upload is never invoking my upload listener. The web beans bootstrapper is loaded fine.