7 Replies Latest reply on Apr 12, 2007 5:33 PM by Thai Dang Vu

    <a4j:commandButton> doesn't work with <t:inputFileUpload>

    Thai Dang Vu Apprentice

      Is it a bug or a property of <a4j:commandButton>?

      I have a form containing a <t:inputFileUpload> from Tomahawk. I use <a4j:commandButton> to submit that form, but the UploadedFile object is always null.

      When playing with RichFaces, Facelets, Ajax4jsf, JSF RI and Tomahawk, I encounter this thing which I cannot explain. So, if you know how it works, could you please explain it to me to broaden my knowledge? Thanks in advance. This is my environment:
      - Ajax4jsf 1.1.1 SNAPSHOT
      - RichFaces 3.0.1 SNAPSHOT
      - Facelets 1.1.12
      - Java 1.6.0
      - Tomcat 6.0.10
      - Tomahawk 1.1.5 SNAPSHOT
      And here is my situation:
      - I build a tab panel like in this code

      <ui:composition template="/WEB-INF/admin/template.xhtml">
       <ui:define name="body">
       <rich:tabPanel headerAlignment="left" switchType="ajax">
       <rich:tab id="userTab" label="User Administration">
       <h:outputText value="Under construction" />
       <rich:tab id="roleTab" label="Role Administration">
       <h:panelGroup id="roleTabGroup">
       <a4j:include viewId="/admin/pieces/role/step2.xhtml" />

      This is the step2.xhtml:
      <h:form enctype="multipart/form-data">
       <h:inputText value="#{role.name}" />
       <t:inputFileUpload value="#{role.attachment}" storage="file" />
       <a4j:commandButton reRender="roleTabGroup" action="#{role.createRole}" value="Create (a4j:commandButton)" />
       <h:commandButton action="#{role.createRole}" value="Create (h:commandButton)" />

      This is the Role.java:
      public class Role {
       private String name;
       private UploadedFile attachment;
       // ... getters & setters
       public String createRole() {
       if (attachment != null) {
       // ...
       else {
       // ...

      To submit the form and change the tab content only, I used <a4j:commandButton>, but if I click on this a4j button, the attachment property is null. When I click the <h:commandButton> the attachment is not null any more and at first I thought evrything will be screwed up because I used normal submit (not Ajax submit). But surprisingly, with the h:commandButton click, only the tab content changed (not the whole page). Could anybody explain this?

      If you want to have this example on your machine and give it a try, here http://download.yousendit.com/60C13A5925AB07D9 is.
      You can download that zip file, unzip it and copy the web directory to the webapps directory of a tomcat 6 (you can rename the web folder to myapp or something) and access this page /web/admin/user-role.jsf, then click on the Role Administration tab, click on the Create New Role link and you'll see evrything for the test. The source code is also in the zip file. The application will write a file to the C:\temp folder, so you should have that folder.