在上传监听器方法中显示错误并更改rich:fileUpload的doneLabel



我必须上传CSV文件,我必须验证文件的一些值,例如不允许负值。然后,我需要验证它,该文件不像"完成"或"上传"。我需要处理显示它的错误。

<rich:fileUpload
    fileUploadListener="#{configClientBean.listener}"
    ontyperejected="alert('some error');"
    maxFilesQuantity="1"
    onuploadcomplete="#{rich:component('waitPanelInterno')}.hide();"
    onfilesubmit="#{rich:component('waitPanelInterno')}.show();"
    render="pnlMensajes, idTableClients, scrollRegistros, outputPanelDetalle"
    autoclear="true">
    <rich:message for="uploadConfigClient" />
    <a4j:ajax event="uploadcomplete" execute="popupFileLoad"
    render="panelCarga, pnlMensajes" />
</rich:fileUpload>

在Backing bean中,我可以验证一些东西,但我不能显示错误或更改"rich:fileUpload"组件的行为,例如不能显示doneLable。

public void listener(FileUploadEvent event) throws Exception {
    try {
        UploadedFile file = event.getUploadedFile();
        ByteArrayInputStream bais = new ByteArrayInputStream(file.getData());
        InputStreamReader is = new InputStreamReader(bais, getMessage("iso"));
        BufferedReader bufRead = new BufferedReader(is);
        while ((registro = bufRead.readLine()) != null) {
            if(cvsLine[1].isEmpty()){
            // stop process
            // Throw error
            }
        }
}

感谢您的宝贵时间。

要添加额外的行为到rich:fileUpload组件,这不是默认的是通过创建自己的文件上传组件(例如myown:fileUpload)基于rich:fileUpload源代码和使用组件开发工具包。

第二个解决方案可以通过添加一个额外的消息字段,在这篇文章中描述:RichFaces fileupload和h:message problem

最新更新