2

我有一个<rich:fileUpload>组件,我想在文件因类型不允许而被拒绝时显示通知。我看到 RF 有一个<rich:notifyMessage>,但是当文件被拒绝时我无法呈现该消息。到目前为止,我有:

    <rich:fileUpload id="fileUploadComp"
                     addLabel="Agregar" clearAllLabel="Quitar todos"
                     clearLabel="Quitar" deleteLabel="Quitar"
                     doneLabel="Completado" uploadLabel="Subir archivos"
                     fileUploadListener="#{uploadBean.doUpload}"
                     acceptedTypes="txt, csv" onclear="onclear(event);"
                     noDuplicate="true">
        <a4j:ajax event="uploadcomplete" render="validationButton"/>
        <a4j:ajax event="typerejected" render="notificationFileRejected"/>
    </rich:fileUpload>

    <rich:notifyMessage for="fileUploadComp" 
                        id="notificationFileRejected"
                        sticky="true"
                        ajaxRendered="true"
                        title="Hello"/>

但是,例如,当我选择 JPEG 时,我看不到任何通知地球。

关于如何实现这一目标的任何想法?

更新

这样做的主要思想是显示一个通知,告诉用户“不允许文件类型”之类的信息。

任何想法?

4

2 回答 2

4

就像是:

<rich:fileUpload id="fileUploadComp"
                 addLabel="Agregar" clearAllLabel="Quitar todos"
                 clearLabel="Quitar" deleteLabel="Quitar"
                 doneLabel="Completado" uploadLabel="Subir archivos"
                 fileUploadListener="#{uploadBean.doUpload}"
                 acceptedTypes="txt, csv" onclear="onclear(event);"
                 ontyperejected="ontyperejected();"
                 noDuplicate="true">
    <a4j:ajax event="uploadcomplete" render="validationButton"/>
</rich:fileUpload>

<a4j:jsFunction name="ontyperejected" actionListener="#{uploadBean.setMessage()}"/>

<rich:notifyMessage stayTime="2000" nonblocking="true"/>

使用java代码:

public void setMessage() {
  String message="Wrong filetype...";
  FacesContext.getCurrentInstance().addMessage("info", new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
}

MAG,米洛·范德泽

于 2012-04-18T07:20:52.707 回答
1

好吧,没有我想要的那么好,但它确实有效。

    <rich:fileUpload id="fileUploadComp"
                     addLabel="Agregar" clearAllLabel="Quitar todos"
                     clearLabel="Quitar" deleteLabel="Quitar"
                     doneLabel="Completado" uploadLabel="Subir archivos"
                     fileUploadListener="#{uploadBean.doUpload}"
                     acceptedTypes="txt, csv" onclear="onclear(event);"
                     ontyperejected="ontyperejected();"  //THIS IS MY TRICK
                     noDuplicate="true">
        <a4j:ajax event="uploadcomplete" render="validationButton"/>
    </rich:fileUpload>

    <script>
        var ontyperejected = function(){
            alert('Archivo inválido. Tipos permitidos: .txt y .csv');
        }
    </script>

只需创建一个 JScript 函数并发送警报消息。瞧。不过,如果有人知道如何实现出现和淡出的那个漂亮的小通知地球,我将非常感激!

于 2012-04-17T19:24:01.900 回答