File filter with primfaces filters with utf8 filter

I have a problem with utf-8 encoding in primers 3. but with this (adding a filter for character encoding in web.xml), my problem is solved. But I have one more filter for file loading mainfaces in my web.xml. On pages where there is a file download, even without downloading anything, my character encoding filter does not work, and the utf-8 character set with unknown values, as in the absence of a filter for downloading. How can I use this filter together?

+7
source share
2 answers

This is a bug in PrimeFaces MultipartRequest . It uses the default character encoding for the form fields instead of the set set in the HTTP servlet request, as HttpServletRequest#setCharacterEncoding() in your character encoding filter (which I assume was mapped to web.xml before PrimeFaces FileUploadFilter ).

Basically, lines 85 and 88 of MultipartRequest in PrimeFaces 3.3

 formParams.get(item.getFieldName()).add(item.getString()); // ... items.add(item.getString()); 

need to change as follows

 formParams.get(item.getFieldName()).add(item.getString(getCharacterEncoding())); // ... items.add(item.getString(getCharacterEncoding())); 

I reported this as issue 4266 . At the same time, it is best to manually correct the incorrect string encoding in the bean action method as follows, assuming that the standard encoding of the server platform is ISO-8859-1:

 string = new String(string.getBytes("ISO-8859-1"), "UTF-8"); 
+12
source

Essentially, you will need the following line of code to fix this:

 new String(file.getFileName().getBytes(Charset.defaultCharset()), "UTF-8") 
+3
source

All Articles