I have a JSF form which contains a Primefaces fileupload component.
The required attribute of the fileupload component is not working; When I hit the form's send button without file attachments, the form is sent and no error message is displayed.
This is the simplified form code I am using for testing:
<h:form id="NewRegistryForm">
<fieldset>
<p:outputLabel for="address" value="Address" />
<h:inputText
name="address"
value="#{registryBean.address}"
required="true"
requiredMessage="Address field is required" />
</fieldset>
<fieldset>
<p>File attachments:</p>
<p:fileUpload
fileUploadListener="#{registryBean.handleFileUpload}"
mode="advanced"
label="Choose file"
multiple="true"
update="registryFileList"
invalidFileMessage="Invalid file type"
sizeLimit="512000"
fileLimit="15"
allowTypes="/(\.|\/)(jpg|png|gif|pdf|odt|doc|docx)$/i"
onstart="setSubmitButtonEnabled(false)"
oncomplete="setSubmitButtonEnabled(true)"
onerror="setSubmitButtonEnabled(true)"
auto="true"
required="true"
requiredMessage="A file attachment is required." />
</fieldset>
<p:dataList id="registryFileList" value="#{registryBean.uploadedFiles}"
var="file" emptyMessage="" >#{file.file.fileName}, #{file.file.size}</p:dataList>
<p:commandButton
type="submit"
action="#{registryBean.sendRequest}"
value="Send form"
validateClient="true" />
</h:form>
The required text input field shows an error message when the field is not filled, but the fileupload component produces no message when no file is attached. What am I doing wrong?