Marcel Hinderlich
Marcel Hinderlich

Reputation: 213

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

I tried to add a <rich:fileUpload> into a richfaces wizard like this one, but when i delete those inputfield (e.g. in step 1), which are required and give error message if not filled, the uploadfield instead is not checked and the wizard switches to the next state

Upvotes: 0

Views: 1109

Answers (1)

jfx
jfx

Reputation: 383

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();
}

Upvotes: 1

Related Questions