RichFaces文件上传和h:消息问题 [英] RichFaces fileupload and h:message problem
问题描述
我正在使用RichFaces 4.我的问题是,消息根本不出现。如果我使用rich:message这个消息会短暂出现,然后消失。
这是控制器: 这就是视图: 在这两种情况下,Firebug报告一个空的消息字段被发送。 b $ b 问题是a4j:ajax标记。这是发送第二个请求,消息被清除。这样做: I am using RichFaces 4. My problem is that the message does not appear at all. If I use rich:message the message appears briefly then dissapears. This is the controller: And this is the view: In both cases Firebug reports an empty message field being sent.
The problem was the a4j:ajax tag. It was sending a second request, and the messages were cleared. This works:
这篇关于RichFaces文件上传和h:消息问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
pre > 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);
$ / code $ / pre
< h:form id =uploadFormenctype =multipart / form-data>
fileUploadListener =#{itemController.uploadListener}
maxFilesQuantity =1
acceptedTypes =csv>
< a4j:ajax event =uploadcompleteexecute =@ nonerender =items,message/>
< / rich:fileUpload>
< / h:表格>
<?xml version ='1.0'encoding ='UTF-8'?>
< partial-response>< changes>< update id =uploadForm:message><![CDATA [< span span =uploadForm:message>< / span>] ]< / update>< update id =j_idt16:items><![CDATA [< table id =j_idt16:items>
< thead>
< tr>
标题
< / th>
< / tr>
< / thead>
< tbody>
< tr>< td>< / td>< / tr>< / tbody>
< / table>
]]>< / update>< update id =javax.faces.ViewState><![CDATA [8859542538952100446:6041172679113548382]]>< / update>< / changes> < /部分响应>
< h:form id =uploadFormenctype =multipart / form-data>
maxFilesQuantity =1
acceptedTypes =csv
render =items,message/>
< / h:表格>
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>
<?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>
<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>