我有一个jsf表单来保存数据,在这个表单中有primefaces的fileuploaded组件,对于我上传的每个文件,它都有一些特定的描述。我正在为此操作使用事件侦听器。现在我的要求是我想限制用户,当我上传文件而不添加描述时,它必须显示“请添加描述”的验证消息但是这个过程应该在之前完成我提交整个表格。
源代码:
<h:panelGrid id="ff" columns="2" cellpadding="8">
<p:outputLabel for="file" value="Description:" styleClass="label"
style="font-weight:bold" />
<p:inputTextarea rows="5" cols="30" id="file"
value="#{manageProject.desc}" required="true"
requiredMessage="Please enter the File desccription" styleClass="input"
counterTemplate="{0} characters remaining." autoResize="false" >
<p:ajax listener="#{manageProject.handlefiles()}"></p:ajax>
</p:inputTextarea>
</h:panelGrid>
<p:fileUpload
fileUploadListener="#{manageProject.handleFileUpload}"
mode="advanced" dragDropSupport="false" multiple="false" update="ff"
sizeLimit="5242880" fileLimit="3" invalidSizeMessage="maximum file size should be 5mb"
>
</p:fileUpload>
豆类:
public void handleFileUpload(FileUploadEvent event) {
docs=new Docs();
try {
byte[] data = new byte[(int) event.getFile().getSize()
];
inputStreams = event.getFile().getInputstream();
inputStreams.read(data);
docs.setImage(data);
docs.setName(event.getFile().getFileName());
System.out.println("desc="+desc);
docs.setDesc(desc);
docses.add(docs);
FacesMessage msg = new FacesMessage(event.getFile().getFileName()+" "+"has been uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}