I have a strange situation where the components on a form are dynamically built and the form is submitted to an action method "create" on a Controller class. Basically the form looks like this:

HtmlPanelGrid
(ROW 1)
--HtmlOutputText
--HtmlPanelGrid
----HtmlSelectOneRadio
----HtmlInputFileUpload
(ROW 2)
--HtmlOutputText
--HtmlPanelGrid
----HtmlSelectOneRadio
----HtmlInputText



Once form is submitted from the "create" method on the Controller class I can lookup the values of the HtmlInputText by doing:

[CODE] String txtBoxValue = request.getParameter(htmlInputText.getId()); [/CODE]

However, I cannot figure out how to access the file that was submitted (the HtmlInputFileUpload). I tried using commons-fileupload as below:

[code]
public InputStream getFileFromRequest(String fieldName, HttpServletRequest request)
{

        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);

        InputStream uploadedStream = null;

        List items;

        try
        {
                // Parse the request
                items = upload.parseRequest(request);
                System.out.println("items.size() "+items.size());
        }
        catch(FileUploadException fue)
        {
                System.out.println("Exception trying to parse request for 
FileItems");
                System.out.println(fue);
                throw new RuntimeException(fue);
        }


        //walk through items in the form
        ....

[/code]

but the items.size() is always zero. I am thinking JSF is intercepting this form before I pass it to the "parse" method and somehow this makes the form un-parsable" for commons-fileupload. If this is true...how can I get the file that was submitted before JSF messes with it...or better yet, how can I get the file that was submitted directly from JSF?


Reply via email to