2 Replies Latest reply on Jan 7, 2011 7:35 AM by shikida

    Custom fileUpload renderer

    shikida

      Hi

       

      I would like to know if it´s feasible to change the fileUpload component renderer, just like other JSF components.

       

      I just can´t find what´s is... that thing below ;-)

       

      <render-kit>
           <renderer>
               <component-family>org.richfaces.component.FileUpload</component-family>
               <renderer-type>org.richfaces.renderkit.html.FileUploadRenderer</renderer-type>
               <renderer-class>?</renderer-class>
           </renderer>
      </render-kit>

       

      Yeah. It´s not there at the Table 6.178.

       

      I just want to change two things

       

      [1] add an hyperlink to the uploaded file, so the user can just download it as well (maybe I can do this in the renderer)

      [2] change the initial list of "loaded" files to those ones present in a specific directory.

       

      Looks like something easy to do, but I must confess I am quite lost, specially on identifying where to look first.

       

      So any help is welcome

       

      Best regards

       

      Leo K.

        • 1. Re: Custom fileUpload renderer
          shikida

          Forgot to say, RF 3.3.3.

          • 2. Re: Custom fileUpload renderer
            shikida

            Well, half of the problem seems to be solved.

             

            To change filenames to links, here´s what I had to do

             

            [1] it seems the renderer is

             

            <render-kit>

                 <renderer>

                     <component-family>org.richfaces.component.FileUpload</component-family>

                     <renderer-type>org.richfaces.renderkit.html.FileUploadRenderer</renderer-type>

                     <renderer-class>org.richfaces.renderkit.html.FileUploadRenderer</renderer-class>

                 </renderer>

            </render-kit>

             

            [2] to get FileUploadRenderer, I had to decompile the class from the jar using jad, since this file seems to be absent of the richfaces source code (I don´t know why exactly, maybe it´s there with another name)

             

            [3] then, in this file, I´ve changed the js file name to something I can change (see bold part)

             

            private final InternetResource scripts[] = {

                    new PrototypeScript(), new AjaxScript(),getResource("/org/richfaces/renderkit/html/scripts/utils.js"), getResource("/org/richfaces/renderkit/html/scripts/json/json-dom.js"), getResource("/org/richfaces/renderkit/html/js/FileUpload2.js"), getResource("/org/richfaces/renderkit/html/js/swfobject.js"), getResource("/org/richfaces/renderkit/html/js/progressBar.js"), getResource("/org/ajax4jsf/javascript/scripts/form.js")

                };

             

            [4] finally, in the js file above, I´ve found FileUploadEntry.template

             

            [newET(function (context) { return Richfaces.evalMacro("fileName",context)})]


            and I´ve replaced it to

             

            [new E('a',{'style':'','onclick': function (context) { return'alert(1);return false;';},      'className':function (context) { return 'rich-fileupload-anc' + Richfaces.evalMacro("labelClassName", context) +Richfaces.evalMacro("className", context); },'href':'#'},

            [new ET(function (context) { returnRichfaces.evalMacro("fileName", context)})])]),

             

            so now, the filename comes inside an anchor that has a javascript action on it (alert), so all I have to do is to put some javascript up there.

             

            so, the other half of my problem seems to be how to get the initial list of uploaded files populated :-)

             

            best regards

             

            Leo K.