1 Reply Latest reply on Feb 21, 2013 7:24 AM by Paul Baker

    rich:fileUpload - h:commandButton action does not fire after a file is uploaded (complete project attached)

    Paul Baker Apprentice

      I added an "Update"  h:commandButton to a form that contains a FileUpload component. 

      When the update button is pressed after a file has been uploaded JSF will skip phases 2-5.

      This effectively clears (resets) all fields to the initial value (other than the uploaded pictures).

      If the update button is pressed a second time then all six phases are processed but this requires form data (other than pictures) to be reentered before pressing update.

      If a file is NOT uploaded then all six phases are processed when the update button is pressed the first time. 

      What is the FileUpload doing that is causing this behavior.  What can be done to remediate?

       

      I have attached the complete project, JBoss console log and pictures that help illustrate the problem that I am facing.

       

      Here is a more detailed description of the problem:

       

      I have taken the existing FileUpload example and added three additional components:

      • outputLabel (Description)
      • inputText
      • commandButton with action updateAction

       

       

      The three additional components can be seen in the image here (index.xhtml)

      001 FileUpload - TR1.jpg

       

      With this form is displayed, I enter text in the description field and upload a single file.

       

       

      Here is what the form looks like after the text has been entered in the description and a single file has been uploaded.

      006 FileUpload - TR1.jpg

       

      From this screen I press "Update" expecting the updateAction method to be called.

       

      Update:  I noticed a small bug with the commandButton but this does not affect the issue...
      The rendered attribute references a non-existing bean.

       

      <h:commandButton id="update" value="Update"
        action="#{fileUploadBean.updateAction}"
        rendered="#{inventoryController.inventoryItem.id != 0}" />
      </h:panelGrid>
      

       

      But that is not what happens... Instead JSF processes phases 1 and 6 (skips 2-5) and this results in the description field being reset to the original value (blank/null).

       

      2013-02-20 08:14:37,034 DEBUG [LifeCycleListener.beforePhase] START PHASE RESTORE_VIEW 1

      2013-02-20 08:14:37,036 DEBUG [LifeCycleListener.afterPhase] END PHASE RESTORE_VIEW 1

      2013-02-20 08:14:37,037 DEBUG [LifeCycleListener.beforePhase] START PHASE RENDER_RESPONSE 6

       

      007 FileUpload - TR1.jpg

       

      Now, with no changes made, if update is pressed again the action method fires and the next screen is rendered.

        

       

      public String updateAction() {
       System.out.println("The Description is: " + desc);
       return "done";
      }
      

       

      2013-02-20 08:18:53,874 INFO  [AbstractLoggingWriter.write] The Description is:

       

      The updateAction completes with "done" and then the navigation rule fires:

       

       

      <navigation-rule>
          <from-view-id>/index.xhtml</from-view-id>
          <navigation-case>
              <from-outcome>done</from-outcome>
              <to-view-id>/underconstruction.xhtml</to-view-id>
          </navigation-case>
      </navigation-rule>
      
      

       

      Finally the next page is displayed:

       

      008 FileUpload - TR1.jpg

       

       

      What am I doing wrong that causes JSF to skip phases 2-5 the first time Update action is requested after a file has been uploaded? 
      Why does the first Update action fail and the next Update action processes as expected?

       

      What can I do to correct this?

       

      Envt:

      • Windows 7
      • Java 6
      • Mojarra-2.1
      • Richfaces 4.3.0 Final

       

      Any help would be welcome.  I'll be happy to provide additional information.

       

      Thanks in advance.

       

      Paul