Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File upload RichFaces文件上载和h:消息问题_File Upload_Jsf 2_Richfaces - Fatal编程技术网

File upload RichFaces文件上载和h:消息问题

File upload RichFaces文件上载和h:消息问题,file-upload,jsf-2,richfaces,File Upload,Jsf 2,Richfaces,我正在使用RichFaces4。我的问题是消息根本没有出现。如果我使用rich:message,消息会短暂出现,然后消失 这是控制器: public void uploadListener(final FileUploadEvent event) throws IOException { final UploadedFile item = event.getUploadedFile(); final FacesContext context = FacesContext.get

我正在使用RichFaces4。我的问题是消息根本没有出现。如果我使用rich:message,消息会短暂出现,然后消失

这是控制器:

public void uploadListener(final FileUploadEvent event) throws IOException
{
    final UploadedFile item = event.getUploadedFile();

    final FacesContext context = FacesContext.getCurrentInstance();
    final Application application = context.getApplication();
    final String messageBundleName = application.getMessageBundle();
    final Locale locale = context.getViewRoot().getLocale();
    final ResourceBundle resourceBundle = ResourceBundle.getBundle(messageBundleName, locale);

    final String msg = resourceBundle.getString("upload.failed");
    final String detailMsgPattern = resourceBundle.getString("upload.failed_detail");

    try
    {
        CSVImporter.doImport(item.getInputStream(), registry, item.getName());
    }
    catch (ParseException e)
    {
        final Object[] params = {item.getName(), e.getMessage()};
        final String detailMsg = MessageFormat.format(detailMsgPattern, params);
        final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);

        context.addMessage("uploadForm:uploader", facesMsg);
    }
    catch (TokenMgrError e)
    {
        final Object[] params = {item.getName(), e.getMessage()};
        final String detailMsg = MessageFormat.format(detailMsgPattern, params);
        final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);

        context.addMessage("uploadForm:uploader", facesMsg);
    }
}
这是一种观点:

<h:form id="uploadForm" enctype="multipart/form-data">
    <h:message id="message" showDetail="true" for="uploader" errorClass="error" warnClass="warning" infoClass="info" fatalClass="fatal"/>
    <rich:fileUpload id="uploader"
             fileUploadListener="#{itemController.uploadListener}"
                 maxFilesQuantity="1"
                 acceptedTypes="csv">
        <a4j:ajax event="uploadcomplete" execute="@none" render="items, message" />
    </rich:fileUpload>
</h:form>

在这两种情况下,Firebug都报告发送了一个空消息字段

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="uploadForm:message"><![CDATA[<span id="uploadForm:message"></span>]]></update><update id="j_idt16:items"><![CDATA[<table id="j_idt16:items">
<thead>
<tr>
<th scope="col">
                        Titles
                    </th>
</tr>
</thead>
<tbody>
<tr><td></td></tr></tbody>
</table>
]]></update><update id="javax.faces.ViewState"><![CDATA[8859542538952100446:6041172679113548382]]></update></changes></partial-response>

]]>
标题
]]>

问题在于a4j:ajax标记。它正在发送第二个请求,消息被清除。这项工作:

<h:form id="uploadForm" enctype="multipart/form-data">
    <h:message id="message" showDetail="true" for="uploader" errorClass="error" warnClass="warning" infoClass="info" fatalClass="fatal"/>
    <rich:fileUpload id="uploader"
             fileUploadListener="#{itemController.uploadListener}"
             maxFilesQuantity="1"
             acceptedTypes="csv"
             render="items, message" />
</h:form>

富上传不会重新发布消息: