如何在表单中创建Richfaces组件<rich:fileupload>

时间:2015-07-28 08:36:42

标签: jsf file-upload jsf-2 richfaces

我尝试将<rich:fileUpload>添加到像this one这样的richfaces向导中,但是当我删除那些输入字段时(例如在步骤1中),这是必需的并且如果未填充则给出错误消息,uploadfield而不是检查,向导切换到下一个状态

1 个答案:

答案 0 :(得分:1)

在required =“true”不适用于rich:fileUpload(Richfaces 4)之后,并且在rich:fileUpload本身(https://issues.jboss.org/browse/RF-5177)上都没有添加自定义字段验证器,我最终添加了一个单独的隐藏字段并对此进行验证以检查文件是否已上载:

<rich:fileUpload id="richUpload" fileUploadListener="#{myForm.fileUploadListener}">
    <a4j:ajax event="uploadcomplete" execute="@none" render="uploadFilesCounter" />
</rich:fileUpload>
<h:inputHidden id="upload" value="#{myForm.uploadFilesCounter}">
    <f:validator validatorId="uploadFilesCounterValidator" />
</h:inputHidden>

并在Managed Bean中:

public void fileUploadListener(FileUploadEvent event) throws Exception {
    this.uploadFilesCounter = uploadFiles.size();
}