13 Replies Latest reply on Apr 29, 2013 6:44 AM by bourasom

    problem with rich:fileUpload

    jeromej

      Hi Ken,

       

      PortletBridge : 3.1.0.Beta3

      Richfaces : 4.2.3.CR1

      JSF : 2.1.13

      Exo : 3.5.3

       

      When i use upload button, we stay client side with the url http://localhost:8080/s2e-portlet-demo-composants/faces/rfRes/fileUploadProgress?ln=org.richfaces&rf_fu_uid_alt=0.6986214399496665 answer is 200 OK 8ms

      No action in listener.

       

      In web.xml :

      <context-param>
      <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>
      <param-value>1000</param-value>
      </context-param>
      <context-param>
      <param-name>org.richfaces.fileUpload.createTempFiles</param-name>
      <param-value>true</param-value>
      </context-param>

       

      xhtml :

      <h:form>

                              <h:panelGrid columns="2" columnClasses="top,top">

                                  <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"

                                      id="upload" acceptedTypes="jpg, gif, png, bmp"

                                      ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');"

                                      maxFilesQuantity="5">

                                      <a4j:ajax event="uploadcomplete" execute="@none" render="info" />

                                  </rich:fileUpload>

                                  <h:panelGroup id="info" layout="block">

                                      <rich:panel bodyClass="info">

                                          <f:facet name="header">

                                              <h:outputText value="Uploaded Files Info" />

                                          </f:facet>

                                          <h:outputText value="No files currently uploaded"

                                              rendered="#{fileUploadBean.size==0}" />

                                          <rich:dataGrid columns="1" value="#{fileUploadBean.files}"

                                              var="file" rowKeyVar="row">

                                              <rich:panel bodyClass="rich-laguna-panel-no-header">

                                                  <h:panelGrid columns="2">

                                                      <a4j:mediaOutput element="img" mimeType="image/jpeg"

                                                          createContent="#{fileUploadBean.paint}" value="#{row}"

                                                          style="width:100px; height:100px;" cacheable="false">

                                                          <f:param value="#{fileUploadBean.timeStamp}" name="time" />

                                                      </a4j:mediaOutput>

                                                      <h:panelGrid columns="2">

                                                          <h:outputText value="File Name:" />

                                                          <h:outputText value="#{file.name}" />

                                                          <h:outputText value="File Length(bytes):" />

                                                          <h:outputText value="#{file.length}" />

                                                      </h:panelGrid>

                                                  </h:panelGrid>

                                              </rich:panel>

                                          </rich:dataGrid>

                                      </rich:panel>

                                      <br />

                                      <a4j:commandButton action="#{fileUploadBean.clearUploadData}"

                                          render="info, upload" value="Clear Uploaded Data"

                                          rendered="#{fileUploadBean.size>0}" />

                                  </h:panelGroup>

                              </h:panelGrid>

                          </h:form>

       

      FileUploadBean.java :

      public class FileUploadBean implements Serializable {

          /**

           *

           */

          private static final long serialVersionUID = 1L;

          private ArrayList<UploadedImage> files = new ArrayList<UploadedImage>();

       

          public void paint(OutputStream stream, Object object) throws IOException {

              stream.write(getFiles().get((Integer) object).getDonnees());

              stream.close();

          }

       

          public void listener(FileUploadEvent event) throws Exception {

              UploadedFile item = event.getUploadedFile();

              UploadedImage file = new UploadedImage();

              file.setLongueur(item.getData().length);

              file.setNom(item.getName());

              file.setDonnees(item.getData());

              files.add(file);

          }

       

          public String clearUploadData() {

              files.clear();

              return null;

          }

       

          public int getSize() {

              if (getFiles().size() > 0) {

                  return getFiles().size();

              } else {

                  return 0;

              }

          }

       

          public long getTimeStamp() {

              return System.currentTimeMillis();

          }

       

          public ArrayList<UploadedImage> getFiles() {

              return files;

          }

       

          public void setFiles(ArrayList<UploadedImage> files) {

              this.files = files;

          }

      }

       

      Do you've any idea ?

      Thanks

        • 1. Re: problem with rich:fileUpload
          jeromej

          More informations :

           

          In richfaces-component-ui-4.2.3.CR1, org.richfaces.request.ProgressControl.java, getProgress always return 0 ...

          • 2. Re: problem with rich:fileUpload
            kenfinni

            Hi Jerome,

             

            I can't see anything obviously wrong with the code, as it looks identical to that in the RF Showcase we package.

             

            The only thing I can think of is that as eXo 3.5.3 is based on GateIn 3.2, it's broken in that version as I've been testing with GateIn 3.4 and 3.5 (master) and it works fine.

             

            Ken

            • 3. Re: problem with rich:fileUpload
              jeromej

              yes eXo 3.5.3 = gatein 3.2.4

              • 4. Re: problem with rich:fileUpload
                jeromej

                I make a test and i confirm :

                Gatein 3.4 = rich:FileUpload OK

                Gatein 3.2 = richFileUpload KO

                • 5. Re: problem with rich:fileUpload
                  terry.lin

                  Hi guys, i am newbie in Richfaces and i face the similar problem. When i add attachment and click upload button , it's work but i can't see Richfaces css, it seems lost css, anyone have idea?

                  The following information are my library version:

                   

                  PortletBridge : 3.1.0.Beta3

                  Richfaces : 4.2.3.Final

                  JSF : 2.1.13

                  Gatein : 3.4.0.Final

                   

                  upload.xhtml:

                   

                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"

                      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">

                          <h:head>          

                          </h:head>

                          <h:body>

                      <h:form>

                          <h:panelGrid columns="2" columnClasses="top,top">

                              <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}" id="upload" acceptedTypes="jpg, gif, png, bmp"

                                  ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');" maxFilesQuantity="5">

                                  <a4j:ajax event="uploadcomplete" execute="@none" render="info" />

                              </rich:fileUpload>

                              <h:panelGroup id="info" layout="block">

                                  <rich:panel bodyClass="info">

                                      <f:facet name="header">

                                          <h:outputText value="Uploaded Files Info" />

                                      </f:facet>

                                      <h:outputText value="No files currently uploaded" rendered="#{fileUploadBean.size==0}" />

                                      <rich:dataGrid columns="1" value="#{fileUploadBean.files}" var="file" rowKeyVar="row">

                                          <rich:panel bodyClass="rich-laguna-panel-no-header">

                                              <h:panelGrid columns="2">

                                                  <a4j:mediaOutput element="img" mimeType="image/jpeg" createContent="#{fileUploadBean.paint}"

                                                      value="#{row}" style="width:100px; height:100px;" cacheable="false">

                                                      <f:param value="#{fileUploadBean.timeStamp}" name="time" />

                                                  </a4j:mediaOutput>

                                                  <h:panelGrid columns="2">

                                                      <h:outputText value="File Name:" />

                                                      <h:outputText value="#{file.name}" />

                                                      <h:outputText value="File Length(bytes):" />

                                                      <h:outputText value="#{file.length}" />

                                                  </h:panelGrid>

                                              </h:panelGrid>

                                          </rich:panel>

                                      </rich:dataGrid>

                                  </rich:panel>

                                  <br />

                                  <a4j:commandButton action="#{fileUploadBean.clearUploadData}" render="info, upload" value="Clear Uploaded Data"

                                      rendered="#{fileUploadBean.size>0}" />

                              </h:panelGroup>

                          </h:panelGrid>

                      </h:form>

                  </h:body>

                   

                  FileUploadBean.java:

                  @ManagedBean

                  @SessionScoped

                  public class FileUploadBean implements Serializable {

                      private ArrayList<UploadedImage> files = new ArrayList<UploadedImage>();

                   

                   

                      public void paint(OutputStream stream, Object object) throws IOException {

                                stream.write(getFiles().get((Integer) object).getData());

                          stream.close();

                      }

                   

                   

                      public void listener(FileUploadEvent event) throws Exception {

                     

                          UploadedFile item = event.getUploadedFile();

                          System.out.println(item.getName());

                          item.write(item.getName());

                         

                      }

                   

                   

                      public String clearUploadData() {

                          files.clear();

                          return null;

                      }

                   

                   

                      public int getSize() {

                          if (getFiles().size() > 0) {

                              return getFiles().size();

                          } else {

                              return 0;

                          }

                      }

                   

                   

                      public long getTimeStamp() {

                          return System.currentTimeMillis();

                      }

                   

                   

                      public ArrayList<UploadedImage> getFiles() {

                          return files;

                      }

                   

                   

                      public void setFiles(ArrayList<UploadedImage> files) {

                          this.files = files;

                      }

                  }

                  • 6. Re: problem with rich:fileUpload
                    kenfinni

                    Terry,

                     

                    I'm not sure what you mean when you say it "lost" the css?  Could you explain what you mean or attach a screen shot of what you're seeing?

                     

                    Ken

                    • 7. Re: problem with rich:fileUpload
                      terry.lin

                      Hi Ken,

                      Thanks for your reply.

                      The following diagram is what i'm seeing.

                      I can't see the component css but after i browser a file and click "Upload", it works.

                      I use firebug tracing and it show "NetworkError: 404 Not Found - http://localhost:8080/javax.faces.resource/progressBar.ecss....".

                      Any idea?

                       

                      Terry

                       

                      2012-10-24 09 21 33.jpg

                      • 8. Re: problem with rich:fileUpload
                        terry.lin

                        Hi Ken,

                        I think i got solution.

                        After i add following configuration into web.xml, it works.

                         

                        <context-param>

                                <param-name>org.richfaces.resourceOptimization.enabled</param-name>

                                <param-value>true</param-value>

                        </context-param>

                        • 9. Re: problem with rich:fileUpload
                          kenfinni

                          Terry,

                           

                          From looking at the urls of css, js and ecss files it was trying to retrieve without optimization, that problem should be fixed in the current master on github and will be part of the CR1 release.

                           

                          In the interim, setting resource optimization to be enabled will resolve it

                          • 10. Re: problem with rich:fileUpload
                            terry.lin

                            Hi Ken,

                            Thanks.

                            • 11. Re: problem with rich:fileUpload
                              nfilotto

                              I've checked on both GatenIn 3.2 and 3.4, it works fine. Your issue seems to come from your code if I replace:

                               

                              <a4j:ajax event="uploadcomplete" execute="@none" render="info" />
                              

                               

                              with the original code which is

                               

                              <a4j:ajax event="uploadcomplete" render="info" />
                              

                               

                              Everything works as expected

                              • 12. Re: problem with rich:fileUpload
                                jeromej

                                Thanks for answer, we can't try yet, but we'll try it for sure.

                                • 13. Re: problem with rich:fileUpload
                                  bourasom

                                  Hello,

                                  I faced a similar issue trying to deploy richfaces portlet in PLF-3.5.6 (Gatein 3.2.6). After foccusing in the problem, I found  this link: https://community.jboss.org/en/portletbridge/blog.The following dependency was helpful to me:

                                  <dependency>
                                      <groupId>org.jboss.portletbridge</groupId>
                                      <artifactId>portletbridge-extension-richfaces</artifactId>
                                      <version>3.2.0.Final</version>
                                      <scope>runtime</scope>
                                  </dependency>

                                  After introducing it, the listner of FileUploadBean is executed without problems.

                                  Hope That this will help You.

                                  Best Regards