How To Use Input Type File In Jsf

 Posted admin
Active6 years ago

I have a situation that I haven't found any questions on yet.

Apr 23, 2013. As JSF 2.2 requires Servlet 3.0 it is finally possible to have the file upload component h:inputFile in the standard. H:inputFile is basically used like any other JSF input component. The upload is stored in a bean property of type javax.servlet.http.Part referenced in the value attribute. As a prerequisite, the form.

Basically, I had to use the twitter-bootstrap typeahead on an input field.

However, this input field was a JSF inputText field like this:

Unfortunately, the twitter-bootstrap typeahead doesn't work with JSF inputText fields - at least, I wasn't able to get it working(If there is a way to do that, please let me know in a comment!).

I had to use a normal input field inside the JSF form, like this:

I got this working perfectly with the typeahead code.

One problem: The bean doesn't get the normal input field's value - that's the reason we were using JSF in the first place.

I need to use a normal input field for the typeahead JS, and I need to use a JSF inputText field in order to get the value to the bean.

Is there a way for me to do this?

SkytigerSkytigerInput
8363 gold badges15 silver badges43 bronze badges

1 Answer

How to use input type file in jsf file

How To Use Input Type File In Jsf 1

I worked around the problem but setting the ID and name attributes on the input field like so:

After doing that, all I had to do in the bean was this following:

The above code worked perfectly for me, though I'm not sure it would work if there were more than one button.

UseSkytigerSkytiger
8363 gold badges15 silver badges43 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged htmljsftwitter-bootstraptypeahead or ask your own question.

- [Instructor] The JSF file output component is new…with JSF 2.2.…Prior to this version, you would've had to rely on third…party providers like Apache and PrimeFaces or worse…raw html to upload files in your JSF application,…which is obviously less than ideal.…We have a fresh page to work with here.…Let's start our work where all JSF input work starts from…the h form.…So throw in an h form over here on line nine.…

Open tags, close tags.…Now heads up, we need to change the encoding attributes…of the h form to support the file output component.…So we'll set enctype to multipart forward slash…form hyphen data.…The multipart slash form data encoding is the best encoding…type to transmit binary data over http.…

This isn't a JSF or java e constraint it's basic http.…That being done lets now introduce…our file upload components.…That's going to be the h inputFile component…open and close the tag.…Now, I've gone ahead and created a view scope bean…named the file upload bean for this exercise.…Let's add a field to bind to the value attributes of…