fileUpload Exception Handling

UI Components for JSF
Post Reply
linen
Posts: 66
Joined: 22 Jun 2011, 19:01

23 Jun 2011, 16:26

Hi I'd like to handle an "exception" or rather validate the file that the user is attempting to upload. If the file already exists on the server, I'd like to display a message to the client informing them of this. I am doing the check in the upload Listener method of my ManagedBean. If I set the value of a property in the bean say "String errorMessage" in the listener method, how can I display this back on the form? I've also tried to instantiate a FacesMessage object and add the message to the FacesContext but it doesn't appear. Is that the correct strategy? Any help is appreciated thanks.
Java 6 -- JSF Mojarra 2.2.1 -- PrimeFaces 4.0 -- Tomcat 7.0.34
Eclipse Juno Java EE -- Mac OS X 10.8.5 -- Safari 6.1.2 -- Chrome 35.0.1916

robert.m
Posts: 226
Joined: 07 Dec 2010, 22:52
Location: Salzburg/Austria

23 Jun 2011, 18:23

Have a look at the showcase: http://www.primefaces.org/showcase-labs ... Simple.jsf
There you can see that this is exactly the way to do it. But make sure you update your message-component after the upload is completed. Otherwise the message is never read from the facescontext

You can exchange the growl component with <p:messages globalOnly="true"> for example. Then all FacesMessages with no component-binding will be displayed.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests