[Ajax4JSF] richfaces上传提示信息显示不出来,不知道啥原因?

gaojiewyh 2009-08-26
不知道啥原因,我的上传老显示不出来,代码我贴到上面,希望大家能帮解决!
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:c="http://java.sun.com/jstl/core">

<h:form>
<a4j:outputPanel ajaxRendered="true">
<rich:messages errorClass="errormsg" infoClass="infomsg"
warnClass="warnmsg" globalOnly="false" />
</a4j:outputPanel>
<h:panelGrid>
<rich:fileUpload fileUploadListener="#{uploadBean.uploadListener}"
maxFilesQuantity="5" autoclear="false" addControlLabel="添加图片"
uploadControlLabel="上传" clearAllControlLabel="清除所有"
clearControlLabel="清除" cancelEntryControlLabel="取消"
stopControlLabel="停止" stopEntryControlLabel="停止" noDuplicate="true"
listHeight="50" listWidth="515" style="height:100;" id="upload"
acceptedTypes="jpg">
</rich:fileUpload>
</h:panelGrid>
</h:form>
</ui:composition>
底层代码

public class UploadBean {
/*
* 构造函数
*/
public UploadBean() {

}

public void uploadListener(UploadEvent event) {
try {
UploadItem item = event.getUploadItem();
String fileName = item.getFileName();
String filepath = ((ServletContext) FacesContext
.getCurrentInstance().getExternalContext().getContext())
.getRealPath("/")
+ "UploadFile/";
// File file = new File(filepath, fileName);
// FileInputStream fis = new FileInputStream(item.getFile());
// FileOutputStream out = new FileOutputStream(file);
// int bytes = 0;
// byte[] bteFile = new byte[1024];
// while ((bytes = fis.read(bteFile)) != -1) {
// out.write(bteFile, 0, bytes);
// }
FacesMessage msg = new FacesMessage();
msg.setSummary("上传失败");
msg.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext.getCurrentInstance().addMessage(null, msg);
// FacesContext.getCurrentInstance().responseComplete();
} catch (Exception e) {
e.printStackTrace();
FacesMessage msg = new FacesMessage();
msg.setSummary("上传失败");
msg.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext.getCurrentInstance().addMessage(null, msg);
// FacesContext.getCurrentInstance().responseComplete();
}
}
}

备注:无论底层如何,就希望异常能跑出来的信息在页面显示,但现在就是显示不了,关于messgae,用了如下的方法也不行。
1、<rich:messages errorClass="errormsg" infoClass="infomsg"
warnClass="warnmsg" globalOnly="true" />

2、
<a4j:outputPanel layout="block" ajaxRendered="true">
<h:messages globalOnly="true" errorClass="errormsg"
infoClass="infomsg" warnClass="warnmsg" />
</a4j:outputPanel>
terryzhou 2009-08-31
定义个String strMessage,到前台显示总可吧
seven0_0 2011-01-19
你好。。你这个原因找出来了吗?我也遇到这个问题
kidneyball 2011-01-20
在<rich:messages>组件上设置属性showSummary="true"试试
Global site tag (gtag.js) - Google Analytics