我正在使用JSF 2.0,primefaces 5和JBoss AS 6(在开始时它会显示以下消息:“[JSFImplManagementDeployer]初始化3个JSF配置:[Mojarra-1.2,MyFaces-2.0,Mojarra-2.0]”)和我我试图使用JSF2 flashScope向下一页发送消息。 这是第一页的ManagedBean:
if (error) {
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_WARN, "An error has occurred", "Please try again.");
FacesContext facesContext = FacesContext.getCurrentInstance();
Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
flash.setKeepMessages(true);
flash.setRedirect(true);
flash.putNow("message", facesMessage);
facesContext.addMessage(null, facesMessage);
try {
facesContext.getExternalContext().redirect("index.xhtml");
}
catch (IOException ex) {
logger.error("IOException during redirection to the home");
}
}
在我的index.xhtml页面中(我希望显示该页面的消息)我插入了标签:
...
<ui:define name="top">
<p:messages />
...
如果发生错误但未显示消息,则重定向有效。怎么了?我是否要在目标页面ManagedBean中编写一些代码?