JSF Myfaces issues

Friday Jul 30, 2010

MyFaces 2.0 Ajax Fileupload

Hello as some people might have noticed myfaces 2.0.2 is out, and with it a set of hidden features which will be exposed over time as the spec matures in those areas, I also gave the code to those features if they caused api changes to the JSF EG so that it might be part of JSF 2.1 and JSF 2.2 or the base for a similar functionality. 

This article is about the file upload support in Apache MyFaces 2.0.2 

    Here is what you have to do:

     

    Then use the code like I do in my working testcase: http://www.pastebin.org/432572

    the important thing is following line:

         <script type="text/javascript">
             myfaces.config =  myfaces.config || {};
             myfaces.config["transportAutoSelection"] = true;
         </script>
    

     

    This enables the auto transport selection, which switches to an IFrame submit in case of a file uploading form submit. This switch cannot be enabled by default because it would break the spec requirements that an xhr post has to be performed at all costs.

    Also XHR level2 is out of the question for now because it is only supported by the newest browsers.

    After that it is straight forward, you can use the fileupload component from Tomahawk 2 (you need to checkout the Tomahawk trunk) for instance, it should work straight out of the box.

    I also did a servlet 3.0 fileupload component for prototyping but the code is too flakey yet (mainly due to spec deficits less due to the component itself) and I cannot really commit it into the core. Instead I made sure that the standard fileupload components perform ok. So it is ready to be used at least from my point of view, but have in mind all this will break compatibility to Mojarra if you use it.

    So using it means you are bound to MyFaces, which is something I do not particularily recommend (hence also donating the prototype code to the EG, I want something like this in the spec)

    Here again is the pastebin to all relevant files:

    If your fileupload is correctly configured this code should work out of the box.

    Comments:

    Hi,

    Would it be possible for you to provide me more info on this?? I have been trying to implement file upload with MyFaces 2.0.2 but haven't had any luck...I am getting SEVERE: View State cannot be reconstructed
    javax.faces.FacesException: javax.faces.application.ViewExpiredException

    when I tried to do file upload...

    Thanks,
    Ricky

    Posted by yhrchan on October 01, 2010 at 11:53 PM CEST #

    Post a Comment:
    • HTML Syntax: NOT allowed

    Calendar

    Feeds

    Search

    Links

    Navigation

    Referers