java - How to extract text from forms marked with enctype:multipart/form-data(JSF 2.0) -
i have jsf page has h:form has textfields , imageupload gadget primefaces
my question is: how can text fields , assign them variable.(the objective separate uploaded image/s text)
-what should do?
-do need filter, that?
-is there easy way achieve primefaces fileupload tool?
this not trivial primefaces 2.2.1. pf 2 file upload handling bit epic fail. under covers it's not trivial upload files ajax. xmlhttprequest
object doesn't support multipart/form-data
requests. lot of "ajaxified" (to have feeling of asynchronous progress) file upload solutions based on hidden iframe or -as in case of pf- using flash. pf 2 1 based on flash , not combinable regular text inputs in order submit data in 1 go.
in pf 3 file upload component has been greatly revised. using "simple" file upload mode problem should solved. however, pf 3 still in beta/alpha stage. need lot of unit tests on webapp see if doesn't break on pf 3.
if pf 3 not option, best bet using tomahawk 2.0 or homebrewing jsf component.
- jsf 2.0 file upload - tomahawk 2.0 file upload tutorial
- uploading files jsf 2.0 , servlet 3.0 - custom file upload component tutorial
as filter, under covers facesservlet
uses httpservletrequest#getparameter()
retrieve submitted values. when you're familiar basic jsp/servlet, should know how works. default html form encoding application/x-www-form-urlencoded
. getparameter()
method relying on this. however, able send binary data along this, such file uploads, default form encoding unsuitable. multipart/form-data
should used instead.
however, form encoding getparameter()
calls won't work anymore then. return null
. @ simplest form, need parse request body manually on per-request basis. see how upload files server using jsp/servlet? however, doesn't work out in combination jsf relying on getparameter()
calls in order set bean properties (model values) submitted values , invoke command button/link action.
so change httpservletrequest
way getparameter()
calls returns proper values. filter
right choice runs before servlet such facesservlet
. filter should parse multipart/form-data
request body, create parameter map , wrap , replace original httpservletrequest
custom implementation returns right parameters , pass request object instead through chain jsf can use transparently "the usual way".
Comments
Post a Comment