voyent
inputFile and fileNamePattern (nice info)  XML
Forum Index -> Components
Author Message
edykory


Joined: 27/Nov/2006 00:00:00
Messages: 332
Offline


Hi there!
For those of you who didn't notice (like me :) ), the inputFile accepts one nice parameter: fileNamePattern, which accepts a regex to specify the filenames it should accept. This can save some handmade checking on your part.
One thing to keep in mind is that this is a regex for filenames, not extensions, so don't use some Windows type of filter *.gif|*.bmp, as it will not work. instead, try something like
".*\\.gif" which will accept files ending in .gif (usually Gif files).
Another thing you should know is that it is using the String.matches to test the matching, so a very useful thing you could do is adding a (?i) at the beginning of the regex, which will make that expression case insensitive (Some people have gif's, others have GIFs, some have doc's, others have DOCs or combinations and you really don't want to use some sort of
".*\\.(((p|Pd|D)(f|F))|((d|D)(o|O)(c|C))|((j|J)(p|P)(g|G))|((g|G)(i|I)(f|F)))" or even a ".*\\.(([pP][dD][fF])|([dD][oO][cC])|([jJ][pP][gG])|([gG][iI][fF]))" ugly thing, when "(?i).*\\.(pdf|doc|jpg|jpeg|gif|png)" will do just fine.
Hope this helps.
Cheers!
Vadus

Joined: 31/Jul/2007 00:00:00
Messages: 1
Offline


sorry, but

<ice:inputFile id="inputFileName"
progressListener="#{inputFile.progress}"
actionListener="#{inputFile.action}"
fileNamePattern="(?i).*\\.(flv|mp4|mp3)"
/>

doesn't work for me. I'v tested it with a .flv file..
Without fileNamePattern everything works fine, but I only want to upload these three content types. Is there a another solution ?
I've read something about filters, defined in the web.xml with MyFaces..

EDIT : oh, it works with : fileNamePattern=".+\.(flv|mp4|mp3)$"
sorry, I'm not a regexp pro..
ccolina

Joined: 30/Jun/2008 00:00:00
Messages: 9
Offline


Thanks for information.

At first I thought that was java.io.FileNameFilter, thinking create properties files or config.xml file to easy modified by no specialist user (only change the extensions) and create my custom filter implementing Filter interface.
But regex expresions are only for advanced users.
Maybe icesoft must make this more easy.

Maybe must create a attribute to make vb expresion reference a java.io.FileNameFilter.
Code:
 <ice:inputFile id="inputFileName"
 progressListener="#{inputFile.progress}"
 actionListener="#{inputFile.action}"
 fileNameFilter="#{inputFile.filter}"
 /> 


I think of create a java.io.FileNameFilter is more flexible.

Thanks anyway! (y)

Casto Colina (Caracas - Venezuela)
edykory


Joined: 27/Nov/2006 00:00:00
Messages: 332
Offline


Man, without any desire to offend you, I think regex should be part of any programmer's arsenal. Especially once you decide to get into using JSF in general and Facelets in particular.

A little bit off topic (and hoping I'm not wrong), be careful:
Checking file sizes or file extensions can be done only server side, so only AFTER the file has been uploaded.

Eduard Korenschi
cyberoblivion

Joined: 21/Jan/2009 00:00:00
Messages: 42
Offline



This didn't work for me either
"(?i).*\\.(pdf|doc|jpg|jpeg|gif|png)" 


I beleive this is how it should be written to ignore case
"(?i:[^.]+[.](jpg|jpeg|gif|png))"
carlosice

Joined: 04/Feb/2009 00:00:00
Messages: 1
Offline


fileNamePattern=".+\.pdf"
fileNamePattern=".+\.pdf|.+\.jpg"

and so on...

this is taken from the tutorials...

<ice:form>
<ice:inputFile id="inputFileComponent1"
actionListener="#{user.uploadActionListener}"
fileNamePattern=".+\.pdf"/>
<br />
<ice:outputText value="#{user.componentStatus}" />
</ice:form>
thundercat.aec@gmail.com

Joined: 20/Dec/2009 00:00:00
Messages: 32
Offline


you can add a list of patterns and it works fine with this
.+\.(pdf|doc|jpg|jpeg|gif|png)

maybe is useful for somebody.-

by
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team