6 Replies Latest reply on Jun 10, 2007 5:23 AM by hispeedsurfer

    Ajax4jsf and Myfaces problem

    frozone

      Hi together!

      I'm having some trouble getting Ajax4jsf started.
      First of all my problem. I got an FileUpload in MyFaces which allows users
      to upload an Excel file. This file is then read and I iterate through the
      rows, saving the data to a mySQL database. As there are more than 3000 rows
      I don't want to let the user wait so long without knowing how far the
      progress is. So I got an attribute called percentage. Now I want to show the
      user the actual progress without rerendering the whole page. This is my
      attempt so far...

      <f:view>
       <h:form id="MyForm" enctype="multipart/form-data">
      
       <h:panelGrid columns="2" border="0" cellspacing="5">
      
       <h:outputLabel for="myFileId" value="File: " />
       <x:inputFileUpload id="myFileId" value="#{myBean.myFile}" storage="file"
      required="true" />
      
       <h:commandButton value="Submit" action="#{ myBean.uploadMyFile}" />
      
       </h:panelGrid>
       <h:outputText value="Please be patient. The file will be saved into the
      database." />
       <br />
      
      
       </h:form>
       <a4j:region>
       <a4j:outputPanel ajaxRendered="true">
       <h:outputText value="#{myBean.uploadPercentage} % done" id="procent" />
       </a4j:outputPanel>
       </a4j:region>
      </f:view>



      I also have getters/setters for the propertiy and I let it change in this
      code snippet
      for (int i = 1; i < sheet.getRows(); i++) {
       uploadPercentage = new Double(i*100 / rowCount).intValue();
       System.out.print(uploadPercentage+"%: ");
       saveToDB( sheet.getRow(i));
       }


      using latest a4jsf and myfaces distribution.
      Does anyone of you have a clue what I made wrong? The percentage simply does
      not update on the page.

      Thanks in advance!

      Regards!


      P.S.: I already got the hint from Adrian Mitev (thanks by the way!) to put the file upload into an iframe and use a4j:poll. But I'm not sure where or how to realize it. Could anyone show me in my code?

        • 1. Re: Ajax4jsf and Myfaces problem

          drop out a4jLregion from your code. It does not make any sense in the case you are trying to use it.
          Adrian is right. You have a form with non-ajax button. When user presses it, there is no room for ajax there. However, it is not possible to have an aajax button instead. It does not work because of the security reason.
          So, using iframe is most suitable way. a4j:poll is required also

          • 2. Re: Ajax4jsf and Myfaces problem
            frozone

            Thanks for your quick answer. Do I have to put the complete form into another jsp and have it run in an iframe?

            e.g.

            <f:view>
             <h2>Semesterupdate</h2>
            
             <h:outputText value="Bitte geben Sie die .xls Datei des aktuellen Semesters an." />
            
             <f:verbatim><iframe src="upload.jsp" /></f:verbatim>
             <a4j:region>
             <a4j:poll interval="500">
             <a4j:outputPanel ajaxRendered="true" >
             <h:outputText value="#{myBean.uploadPercentage} % erledigt." id="procent" />
             </a4j:outputPanel>
             </a4j:poll>
             </a4j:region>
            </f:view>
            


            and in the upload.jsp
            <f:view>
            <h:form id="MyForm" enctype="multipart/form-data">
             <h:panelGrid columns="2" border="0" cellspacing="5">
            
             <h:outputLabel for="myFileId" value="Datei: " />
             <x:inputFileUpload id="myFileId" value="#{myBean.myFile}" storage="file" required="true" />
            
             <h:commandButton value="Hochladen" action="#{myBean.uploadMyFile}" />
             </h:panelGrid>
             <h:messages style="color:red;"/>
             <h:outputText value="Bitte haben sie einen Moment Geduld. Das Speichern in die Datenbank kann bis zu 2 Minuten dauern." />
             <br />
             </h:form>
            </f:view>
            


            Thanks once again for the answers.
            I tried getting it started this way already. But does not work. Seems as if I still got an error inside.


            • 3. Re: Ajax4jsf and Myfaces problem

              you need to have a h:form around the poll

              • 4. Re: Ajax4jsf and Myfaces problem

                do you have a small application to test?

                • 5. Re: Ajax4jsf and Myfaces problem
                  frozone

                  Hi Sergey,

                  thanks once again for your answer. But unfortunetely it still does not work. I kept the tags, because I heard of an issue using myfaces and a4jsf togther.

                  :-(

                  • 6. Re: Ajax4jsf and Myfaces problem
                    hispeedsurfer

                    hi frozone,

                    I tried to put a iframe to my page in the same way like you with xhtml.

                    But this frame cannot be displayed: 403 - access dinied.