I'm using the component rich:fileUpload for uploading files to my server the problem is that those files go along with a form that the user fills, so I wanna use one external button for doing this.
The user select the files to upload, fill the form and then click a "Submit" button at the bottom of the page. This upload the file with the form. I've tried it like this:
I'm able to hide the button inside the panel of fileUpload so the user don't click on it.
<rich:fileUpload id="fileUploadId"
style="width: 100%; height: 130px;"
fileUploadListener="#{documentsBean.listener}"
maxFilesQuantity="1"
uploadButtonClass="display-none"
uploadButtonClassDisabled="display-none">
</rich:fileUpload>
And what I've tried with the button is
<a4j: commandButton id="uploadFormButton"
value="Attach"
onclick="#{rich:component('fileUploadId')}.submitForm();"
oncomplete="#{rich:component('fileUploadId')}.clear(); return false;"/>
But it doesn't work.
I don't know if there is a way to do exactly what you want, but here is another solution you can use :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:st="http://spectotechnologies.com/jsf"
xmlns:t="http://myfaces.apache.org/tomahawk">
...
<h:form enctype="multipart/form-data">
... your fields ...
<t:inputFileUpload value="#{bean.document}" />
<h:commandButton value="Submit" actionListener="#{bean.onButtonSubmitClick}" />
</h:form>
</html>
and the bean :
@ManagedBean
@RequestScoped
public class Bean
{
private UploadedFile m_oDocument;
public void setDocument(UploadedFile p_oDocument)
{
m_oDocument = p_oDocument;
}
@UploadedFileNotEmpty
@UploadedFileSize(max="10000000")
@UploadedFileExtension(accept="doc,docx,pdf,txt,rtf,xls,xlsx,zip,rar,jpg,jpeg,jpe,bmp,gif,png,csv,ppt,pptx,odp,pic,odt,ods")
public UploadedFile getDocument()
{
return m_oDocument;
}
public void onButtonSubmitClick(ActionEvent p_oEvent)
{
...
}
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With