确定p:growl中消息/咆哮的严重性

时间:2018-01-23 20:43:53

标签: jsf primefaces exception-handling growl

我的支持bean中有以下代码:

sudo

在jsf:

try {
    contractService.create(selectedContract);
    conversation.end();
    return "search?faces-redirect=true";
} catch (ActiveContractExistsException e) {
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, null, e.getMessage()));
    return null;
}

<p:growl id="growl" showDetail="true" showSummary="false" closable="true" autoUpdate="true"/>

结果我得到了:

enter image description here

就像你可以看到这远离<p:commandButton value="Save" actionListener="#{contractView.update}" update="growl"/> 。但最有趣的部分是当我的代码跟随时(在SEVERITY_ERROR块之外添加消息):

catch

然后一切都很好:

enter image description here

如何在处理异常时将 try { contractService.create(selectedContract); conversation.end(); FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, null, "Some message")); return "search?faces-redirect=true"; } catch (ActiveContractExistsException e) { //FacesContext context = FacesContext.getCurrentInstance(); //context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, null, "Some message"/*e.getMessage()*/)); return null; } 级别设置为我的消息?

1 个答案:

答案 0 :(得分:0)

我的问题与EE容器有关。如果我没有从EJBException扩展,它们会自动换行,因此块@ApplicationException不会执行。有两种方法可以解决我的问题:

  1. 从EJBException扩展我的自定义异常
  2. static class A { public static string GetPath() { return "C:\\"; } } 注释添加到我的类例外