【发布时间】:2016-11-15 07:57:49
【问题描述】:
我正在使用Prime Faces,我希望用户从索引页面开始,按下按钮调用函数 (registrarUsuario) 以重新加载索引页面并显示上下文消息。我的问题是我的应用程序没有显示该消息。
这是我的代码:
index.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:b="http://bootsfaces.net/ui">
...
<h:form>
<b:commandButton action = "#{registroUsuario.registrarUsuario}" value = "call function"/>
</h:form>
....
RegistroUsuario.java:
public void registrarUsuario() throws IOException, Exception {
try {
//another code
FacesMessage message = new FacesMessage(":D", "message");
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, message);
} catch (Exception e) {
FacesMessage message = new FacesMessage("Falla", e.toString());
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, message);
}finally{
FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
}
}
谢谢!
【问题讨论】: