-
1. Re: test on the file name <rich:fileUpload>
ilya_shaikovsky Jan 14, 2011 5:16 AM (in response to ando0098)unfortunatelly need to admit that there is no simple way. you can't use ajax to upload the file. our fileUpload actually uses submits from iframes in order to achieve assync of upload requests. so a4j:support will not work. And with current component functionality you really has single place to validate - in uploadListener.
B.t.w. if client side solution is enough - just try to handle onadd by JS. check dcumentation to read how to get access to file entry in handler and return false if it doesn't fit requirements.
Let me know if will not works and I will make tests on our side.
-
2. test on the file name <rich:fileUpload>
ando0098 Jan 17, 2011 4:32 AM (in response to ilya_shaikovsky)i did this and it works fine :
Page:
<h:from>
<h:message id="errorFile" for="upload" class="error" />
<rich:fileUpload
fileUploadListener="#{MyBean.listener}"
rendered="true" maxFilesQuantity="1" id="upload"
immediateUpload="false" acceptedTypes="txt"
allowFlash="false" noDuplicate="true"
listHeight="100px">
<a4j:support event="onadd" onsubmit="document.getElementById('hiddenId').value=$('upload').component.entries[0].fileName;"
action="#{MyBean.validateUploadItem}" reRender="#{MyBean.item}" />
<f:facet name="label">
<h:outputText value="{_KB}KB copié sur {KB}KB {mm}:{ss}" />
</f:facet>
</rich:fileUpload>
<h:inputHidden value="#{MyBean.uploadItem}" id="hiddenId" />
</h:form>
Bean:
public String validateUploadItem() {
item="errorFile";
if (!validate(uploadItem)) {
item=item+",upload";
generateErrorMessage();
}
return "";
}
I have a small problam, the error message didn't display.
for this, i used javascript and i works fine
<a4j:support event="onadd" onsubmit="document.getElementById('hiddenId').value=$('upload').component.entries[0].fileName;"
action="#{MyBean.validateUploadItem}" reRender="#{MyBean.item}"
oncomplete="if(#{MyBean.showErrorMessage}) alert(#{msg.invalid_file_name});" />
thx.