tags:

views:

2274

answers:

4
+1  Q: 

JSF 2.0 Components

Does anyone know of any good resources for JSF 2.0 components? I'm trying to develop a file upload component to teach myself JSF 2.0 and Servlet 3.0 but I'm having a hard time finding resources. I've been looking at the Mojarra 2.0.2 source but it seems like a lot of their stuff is still using JSF 1.x concepts. Any insight is appreciated.

A: 

I have some examples here : http://mcatr.blogspot.com/search/label/JSF hope it helps

MCA
A: 

The standard JSF components do not include a file upload component. This component is usually provided in in 3rd-party JSF component libraries such as myfaces, icefaces, etc...

At the moment I don't know of any JSF 2.0 component libraries that are ready yet (other than the spec standard) so I'm unaware of any file upload components that are JSF 2.0 ready.

Johnny Keys
+6  A: 

Last week at the Sun forum someone has posted an example of a custom JSF 2.0 file upload component, but it is built up on Apache Commons FileUpload API and the code has here and there several flaws, but it may be enough information to start with. Be careful though, some of those flaws are serious: JavaServer Faces - Creating JSF 2.0 File Upload Component

By a coincidence, I was lately also playing with the idea around a JSF 2.0 file upload component in combination with the new Servlet 3.0 multipart support for a new article at my blog. It's only hard to figure what's the best way to create a JSF 2.0 custom component (a @FacesComponent), Google reveals a little, only this blog of Jim Driscoll is somewhat useful. Further it's nowhere explained in the Java EE 6 tutorial and even the JSF 2.0 specification tells nothing about it.

Update: I got it to work, but there is one major disadvantage: I can't make use of the Servlet 3.0 @MultipartConfig annotation to specify the upload location and the max file size. This get activated only if set on a Servlet, not on a Filter. As the FacesServlet is declared final and the JSF provides no facility to have another Servlet to process the request before the FacesServlet kicks in, I don't see any clean ways to make use of the annotation. Normally the upload location is to be configured in the annotation, but this is easy workaroundable by using Part#getInputStream() instead of Part#write(). The max file size is in no way configureable without the annotation, so you'll have to live with "unlimited size uploads" and the fact that you can only validate it when the upload is complete (which may on the other hand be an advantage, because the enduser would otherwise face an ugly HTTP 500 error).

Update 2:: here's the blog: http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html Hope this helps :)

BalusC
+2  A: 

I would highly recommend taking a look into PrimeFaces: http://primefaces.org/

It is a component suite built for JSF (and specifically supports JSF 2.0) under open-source license, uses YahooUI under the covers, and supports your file upload scenario as well.

ngeek
digitaljoel