Thursday, 15 May 2014

java - Validate File before getting uploaded using h:inputFile and javax.servlet.http.Part in JSF -



java - Validate File before getting uploaded using h:inputFile and javax.servlet.http.Part in JSF -

i working on jsf web project uses h:inputfile facility upload files.i bind value of h:inputfile backing bean property of type javax.servelt.http.part

<h:inputfile id="inputfile" validator="#{bean.validatefile}" value="#{bean.part}"/>

also utilize next file validation strategy in same backing bean:

public void validatefile(facescontext con, uicomponent comp, object value) { part p = (part) value; list<facesmessage> list = new arraylist<>(); if (p.getsize() == 0) { list.add(new facesmessage("file size small")); } if (p.getsize()>maxsize) { list.add(new facesmessage("file size big")); } if (!list.isempty()) { throw new validatorexception(list); } }

my question: using part interface cause whole file uploaded server side , then validated (i.e size) on submitting form?

as experiencing in local host(glass fish v.4), see message in the left corner of chrome browser indicating file upload progress , after in case of file validation error validation message.i worry in real situations(like slow net connections),it pretty inconvenient way send size validation error after uploading file!

please help me, , if case assume send alternative solution.

thanks in advance!

this normal behaviour. server needs access file validate (content, size...), , access can granted through user interaction, e.g. form submitting.

see : icefaces inputfile getting file content without upload

java validation jsf jsf-2

No comments:

Post a Comment