简体   繁体   中英

How do I make Richfaces component <rich:fileUpload> be required in form

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

After the required="true" doesn't work for rich:fileUpload (Richfaces 4), and neither does adding a custom field validator on the rich:fileUpload itself ( https://issues.jboss.org/browse/RF-5177 ), I ended up with adding a separate hidden field and doing the validation on this one to check if files have been uploaded:

<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>

and in the Managed Bean:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM