How can I upload multiple files with JSF 2.2

前端 未结 3 1930
旧时难觅i
旧时难觅i 2020-12-16 00:34

I am trying to add a multiple file upload using h:inputFile. I had a quick look through the source code and it appears that it does not have the option to rende

3条回答
  •  不知归路
    2020-12-16 00:48

    I think it is possible to use multiple file upload using the standard JSF 2.2 using the passthrough tag.

    Step 1:

    
    ...
    
    
        
        ...
    

    Step 2:

    The JSF renderer class FileRenderer for the javax.faces.File type of the javax.faces.Input family of components doesn't handle this case correctly.

    Instead, as it iterates through the parts of the form, it just overwrites the preceding part with each file in the uploaded collection.

    I think a better strategy is to always have the value of the component be a List instead of just Part as suggested here and implemented here.

    Step 3:

    The last thing to make it work is to configure such modified multiple file renderer class in faces-config.xml adding the following to the root element:

    
        
            Multiple File Renderer
            javax.faces.Input
            javax.faces.File
            com.example.MultipleFileRenderer
        
    
    

提交回复
热议问题