-
1. RichFaces 4: FileUpload Clear Event
ilya_shaikovsky Apr 25, 2011 2:20 AM (in response to lessonz)actually that looks like a bug http://docs.jboss.org/richfaces/latest_4_0_X/vdldoc/ do not contains such handler. so please add jira issue on that.
-
2. RichFaces 4: FileUpload Clear Event
bcn May 11, 2011 12:39 PM (in response to ilya_shaikovsky)Yeah, a clear listener is urgently necessary!
Both for the clear all as for individual clear actions.
Is the jira issue created already?
Thanks,
Ulrich
-
-
4. Re: RichFaces 4: FileUpload Clear Event
bleathem Sep 28, 2011 12:41 PM (in response to lessonz)Issue RF-10952 has been resolved. It will be available when RichFaces 4.1.0.M3 has been released. (soon!)
-
5. Re: RichFaces 4: FileUpload Clear Event
bcn Nov 28, 2011 8:30 AM (in response to bleathem)Hello,
I tried the clear handler like this:
<rich:fileUpload>
<a4j:ajax event="clear" listener="#{bean.clearUpload}" />
</rich:fileUpload>
public void clearUpload() {...}
The bean method is called when Clear All is clicked as well as when an individual item is removed.
But how can I distinguish these two cases and, in the latter, how can I find out in the bean method which item was removed?
Thanks
-
6. Re: RichFaces 4: FileUpload Clear Event
bleathem Nov 28, 2011 11:55 AM (in response to bcn)Your listener might be able to inspect the list of items cleared from the AjaxBehaviorEvent parameter.
-
7. Re: RichFaces 4: FileUpload Clear Event
bcn Nov 28, 2011 12:47 PM (in response to bleathem)Okay, the bean method can be
public void clearUpload(AjaxBehaviorEvent event) {...}
but I am unable to find out the deleted item from the event object.
I can get UIFileUpload from event.getSource(), but still no idea where to get the deleted file from.
Thanks
-
8. Re: RichFaces 4: FileUpload Clear Event
bcn Nov 28, 2011 2:55 PM (in response to bcn)I think it is impossible to determine which file was cleared. The parameter of the listener should be a FileUploadEvent, otherwise there is no reference to the file. The component has no "var" attribute to bind a bean variable to. One could define a f:param on the a4j:ajax tag, but to what could its value be set? I am stuck.
-
9. Re: RichFaces 4: FileUpload Clear Event
bleathem Nov 28, 2011 3:14 PM (in response to bcn)Hmm, there are few other events you can tap into, but I'm curious, what's your use case for knowing which file has been cleared?
-
10. Re: RichFaces 4: FileUpload Clear Event
bcn Nov 28, 2011 3:22 PM (in response to bleathem)The user uploads several files, then clears only one of them. So I have to remove only that item from my list of uploaded items in the bean, not all of them.
-
11. Re: RichFaces 4: FileUpload Clear Event
bleathem Nov 29, 2011 1:43 AM (in response to bleathem)Having dug into this, it is apparent there are a number of problems with the clear handler of the file upload component. I've got some working code showing how you can remove the uploaded files from your backing bean, but I had to create and resolve RF-11744 to do so. You'll need a recent 4.1.0-SNAPSHOT to try this out, or wait for the next release (CR2). I've included code snippets here, but you can see the code in context in the dev-examples.
Consider the autocomplete tag: (From: autocomplete.xhtml)
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}" onclear="onclear(event)" ... > <a4j:ajax event="uploadcomplete" execute="@none" render="info" /> </rich:fileUpload>
The onclear handler is a javascript method that digs the file list out of the javascript event:
var onclear = function (event) { var data = event.rf.data; for (var i in data) { var item = data[i]; removeFile(item.name); }
Then you'll need a <a4j:jsFunction> for the onclear handler to call into, and initiate the ajax call:
<a4j:jsFunction name="removeFile" render="info" action="#{fileUploadBean.clearFile}"> <a4j:param name="clearedFile" assignTo="#{fileUploadBean.clearedFile}" /> </a4j:jsFunction>
I'm pretty sure this can be done with a RichFaces javascript API call, but I couldn't find it off hand.
You'll then have a backing bean (see: FileUploadBean.java) method "fileUploadBean.clearFile" that will be called once for each file removed, where the file to remove is stored in the backing bean property "clearedFile".
This is functional, but gross - I consider it a workaround. Would you please file a jira asking for a JSF behaviour to be added to the fileuplaod component, to make it easier to write onclear listeners? We can address that in the 4.2 release timeframe.
Brian
-