8 Replies Latest reply on Apr 14, 2008 10:53 AM by ilya_shaikovsky

    a4j:mediaOutput problem in firefox

    daedlus

      Hi

      i have below code which displays an image .this can be refreshed using a a4j button.
      This works fine in IE6.
      i am facing a prob in firefox 2.0.0.x.first time image is displayed but on clicking refresh button it doesnt seem to show refreshed image.if i clear the fire fox cache then it seems to update correctly.

      Is this a bug in ajax4jsf? or am i missing somthg.


      
      <a4j:mediaOutput id="id_graph" element="img" cacheable="false" session="true" createContent="#{bean.paint}" value="#{imageCustomizer}" mimeType="image/png" />
      
      


        • 1. Re: a4j:mediaOutput problem in firefox

          does the value attribute is changed during the requests?

          • 2. Re: a4j:mediaOutput problem in firefox
            daedlus

            the value attribute is not changed.It has some constants defined.-width,height,etc

            • 3. Re: a4j:mediaOutput problem in firefox
              ilya_shaikovsky

              add some random prefics to value to prevent caching.

              • 4. Re: a4j:mediaOutput problem in firefox

                What it the version of the RichFaces (Ajax4jsf), BTW? It was a bug sometime ago when cacheable="false" was ignored.

                • 5. Re: a4j:mediaOutput problem in firefox
                  daedlus

                  am using 3.1.2 GA.

                  adding random prefix to value , how?

                  currently ImageCustomizer has constants declared, do i create a private member in ImageCustomizer and assign it a random value in its getter?

                  or

                  u mean like this?
                  value="#{myBean.randomNumber}#{imageCustomizer}"

                  • 6. Re: a4j:mediaOutput problem in firefox
                    daedlus

                    ok..if value is varied every time then it works in Firefox.

                    • 7. Re: a4j:mediaOutput problem in firefox

                      After upload a new image, firefox not show the new image until you clear cache. works fine in IE. It is possible to make the value param dynamic?

                      jspx

                      <rich:fileUpload
                       fileUploadListener="#{fileUploadBean.listener}"
                       maxFilesQuantity="#{fileUploadBean.uploadsAvailable}"
                       immediateUpload="#{fileUploadBean.autoUpload}"
                       acceptedTypes="jpg, gif, png, bmp" listHeight="60">
                       <f:facet name="label">
                       <h:outputText value="#{msg.rich_file_upload_label}"/>
                       </f:facet>
                       <a4j:support event="onuploadcomplete" reRender="preview"/>
                      </rich:fileUpload>
                      
                      
                      <rich:dataGrid value="#{fileUploadBean.files}" var="file" columns="1" rowKeyVar="row">
                       <a4j:commandLink action="#{fileUploadBean.clearUploadData}" reRender="upload,preview">
                       <a4j:mediaOutput cacheable="false"
                       rendered="#{fileUploadBean.size == 1}" element="img"
                       mimeType="image/jpeg" createContent="#{fileUploadBean.paint}"
                       value="#{row}" border="0" style="max-height:200px; max-width: 166px;"/>
                       </a4j:commandLink>
                      </rich:dataGrid>


                      FileUploadBean.class

                      @Stateful
                      @Name("fileUploadBean")
                      @Scope(ScopeType.SESSION)
                      public class FileUploadBean implements FileUploadBeanIF {
                      
                       private ArrayList<File> files = new ArrayList<File>();
                       private int uploadsAvailable = 1;
                       private boolean autoUpload = true;
                       public int getSize() {
                       if (getFiles().size()>0){
                       return getFiles().size();
                       }else
                       {
                       return 0;
                       }
                       }
                      
                      
                       @Destroy
                       @Remove
                       public void remove(){}
                      
                       public FileUploadBean() {
                       }
                      
                       public void paint(OutputStream stream, Object object) throws IOException {
                       stream.write(getFiles().get((Integer)object).getData());
                       }
                       public void listener(UploadEvent event) throws IOException {
                       UploadItem item = event.getUploadItem();
                       File file = new File();
                       file.setLength(item.getData().length);
                       file.setName(item.getFileName());
                       file.setData(item.getData());
                       file.setUploadDate(new Date(System.currentTimeMillis()));
                       files.add(file);
                       uploadsAvailable--;
                       }
                      
                       public String clearUploadData() {
                       files.clear();
                       setUploadsAvailable(1);
                       return null;
                       }
                      
                       public ArrayList<File> getFiles() {
                       return files;
                       }
                      
                       public void setFiles(ArrayList<File> files) {
                       this.files = files;
                       }
                      
                       public int getUploadsAvailable() {
                       return uploadsAvailable;
                       }
                      
                       public void setUploadsAvailable(int uploadsAvailable) {
                       this.uploadsAvailable = uploadsAvailable;
                       }
                      
                       public boolean isAutoUpload() {
                       return autoUpload;
                       }
                      
                       public void setAutoUpload(boolean autoUpload) {
                       this.autoUpload = autoUpload;
                       }
                      
                      
                      
                      }



                      File.class

                      public class File implements Serializable {
                      
                       private String Name;
                       private long length;
                       private Date uploadDate;
                       private byte[] data;
                       public byte[] getData() {
                       return data;
                       }
                      
                       public void setData(byte[] data) {
                       this.data = data;
                       }
                       public String getName() {
                       return Name;
                       }
                       public void setName(String name) {
                       Name = name;
                       }
                       public long getLength() {
                       return length;
                       }
                       public void setLength(long length) {
                       this.length = length;
                       }
                      
                      
                       public Date getUploadDate() {
                       return uploadDate;
                       }
                      
                       public void setUploadDate(Date uploadDate) {
                       this.uploadDate = uploadDate;
                       }
                      }
                      



                      • 8. Re: a4j:mediaOutput problem in firefox
                        ilya_shaikovsky

                        please read above how it was fixed for daedlus ;)