Currently, I would say no. But I think it is something that can be done.

The trick is simply to change the files variable in the Wrapper and use:
Map<String,FileItem[]> files = new HashMap<String,FileItem[]>();
Then, add all files to the map and only resolve the index at the very end to 
obtain:
Map<String,FileItem> filesWithConvertedParameters;
Then, just pass it to Stripes.

I think it’s what I wanted to in my next step, but I’ve stopped working on this 
because it’s been abandoned due to limited support of HTML 5 in old browsers.

Christian

De : Samuel Santos [mailto:sama...@gmail.com]
Envoyé : January-12-12 3:11 PM
À : Stripes Users List
Objet : Re: [Stripes-users] File inputs with the new "multiple" attribute

Does it also work with an array (does not need an index)?

In the ActionBean:
   @Validate
   public FileBean[] files;

In the JSP:
<stripes-dynamic:file id="files" name="files[]" multiple="multiple"/>

Cheers,

--
Samuel Santos
http://www.samaxes.com/

On Thu, Jan 12, 2012 at 7:57 PM, Mike McNally 
<emmecin...@gmail.com<mailto:emmecin...@gmail.com>> wrote:
whoa that's awesome ... I'll def. give that a try.

Thanks!!!

On Thu, Jan 12, 2012 at 1:19 PM, Poitras Christian
<christian.poit...@ircm.qc.ca<mailto:christian.poit...@ircm.qc.ca>> wrote:
> Hi,
>
> I've managed to create a workarounf for this a while ago.
> I thought about adding it to StripesStuff project, but it would be better if 
> it was in Stripes itself.
> I think it would be easy to change it so that we won't need to add a "[0]" at 
> the end of the name element.
>
> In the ActionBean:
>    @Validate
>    public List<FileBean> files;
>
> In the JSP:
> <stripes-dynamic:file id="files" name="files[0]" multiple="multiple"/>
>
> You need a new 
> net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper.
>    @SuppressWarnings("unchecked")
>    public void build(HttpServletRequest request, File tempDir, long 
> maxPostSize)
>            throws IOException, FileUploadLimitExceededException {
>        String charset;
>        Map<String,FileItem> files = new HashMap<String,FileItem>();
>        Map<String,String[]> parameters = new HashMap<String, String[]>();
>
>        try {
>            charset = request.getCharacterEncoding();
>            DiskFileItemFactory factory = new DiskFileItemFactory();
>            factory.setRepository(tempDir);
>            ServletFileUpload upload = new ServletFileUpload(factory);
>            upload.setSizeMax(maxPostSize);
>
>            List<FileItem> items = upload.parseRequest(request);
>            Map<String,List<String>> params = new HashMap<String, 
> List<String>>();
>
>            for (FileItem item : items) {
>                // If it's a form field, add the string value to the list
>                if (item.isFormField()) {
>                    List<String> values = params.get(item.getFieldName());
>                    if (values == null) {
>                        values = new ArrayList<String>();
>                        params.put(item.getFieldName(), values);
>                    }
>                    values.add(charset == null ? item.getString() : 
> item.getString(charset));
>                }
>                // Else store the file param
>                else {
>                    processFile(item, files);
>                }
>            }
>
>            // Now convert them down into the usual map of String->String[]
>            for (Map.Entry<String,List<String>> entry : params.entrySet()) {
>                List<String> values = entry.getValue();
>                parameters.put(entry.getKey(), values.toArray(new 
> String[values.size()]));
>            }
>        }
>        catch (FileUploadBase.SizeLimitExceededException slee) {
>            throw new FileUploadLimitExceededException(maxPostSize, 
> slee.getActualSize());
>        }
>        catch (FileUploadException fue) {
>            IOException ioe = new IOException("Could not parse and cache file 
> upload data.");
>            ioe.initCause(fue);
>            throw ioe;
>        }
>
>        try {
>            Field charsetField = 
> net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper.class.getDeclaredField("charset");
>            if (!charsetField.isAccessible()) {
>                charsetField.setAccessible(true);
>            }
>            charsetField.set(this, charset);
>            Field filesField = 
> net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper.class.getDeclaredField("files");
>            if (!filesField.isAccessible()) {
>                filesField.setAccessible(true);
>            }
>            filesField.set(this, files);
>            Field parametersField = 
> net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper.class.getDeclaredField("parameters");
>            if (!parametersField.isAccessible()) {
>                parametersField.setAccessible(true);
>            }
>            parametersField.set(this, parameters);
>        } catch (NoSuchFieldException e) {
>            throw new RuntimeException("Could not set fields in super class", 
> e);
>        } catch (IllegalAccessException e) {
>            throw new RuntimeException("Could not set fields in super class", 
> e);
>        }
>    }
>    private void processFile(FileItem item, Map<String,FileItem> files) {
>        if (item.getFieldName().endsWith("[0]")
>                && files.containsKey(item.getFieldName())) {
>            String baseName = item.getFieldName().substring(0, 
> item.getFieldName().length() - 3);
>            int index = 0;
>            while (files.containsKey(baseName + "[" + index + "]")) {
>                index++;
>            }
>            log.trace("renaming file parameter " + item.getFieldName() + " to 
> " + baseName + "[" + index + "]");
>            files.put(baseName + "[" + index + "]", item);
>        } else {
>            files.put(item.getFieldName(), item);
>        }
>    }
>
> Christian
>
> -----Message d'origine-----
> De : Mike McNally [mailto:emmecin...@gmail.com<mailto:emmecin...@gmail.com>]
> Envoyé : January-12-12 12:25 PM
> À : Stripes Users List
> Objet : [Stripes-users] File inputs with the new "multiple" attribute
>
> In newer browsers, it's possible to give input elements of type "file"
> the "multiple" attribute. That tells the browser to allow more than
> one file to be selected in the file chooser. That, in turn, results in
> a multi-valued request parameter.
>
> When I try this, however, it doesn't work, a situation which I think
> is documented on the wiki.  However that documentation was probably
> written before the advent of the "multiple" attribute, so the
> painfulness of the situation was not as evident then (and thus the
> indexed parameter name solution seemed quite reasonable). There's no
> way to fix this however; the browser is completely in charge of
> preparing the POST data.
>
> My question is, what is it that would have to be fixed in order to
> support "multiple" file parameters?  The web is moving pretty fast
> nowadays :-)
>
>
> --
> Turtle, turtle, on the ground,
> Pink and shiny, turn around.
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Mar 27 - Feb 2
> Save $400 by Jan. 27
> Register now!
> http://p.sf.net/sfu/rsa-sfdev2dev2
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net<mailto:Stripes-users@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Mar 27 - Feb 2
> Save $400 by Jan. 27
> Register now!
> http://p.sf.net/sfu/rsa-sfdev2dev2
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net<mailto:Stripes-users@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/stripes-users



--
Turtle, turtle, on the ground,
Pink and shiny, turn around.

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net<mailto:Stripes-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to