Determination severity of message/growl in p:growl

500 Views Asked by At

I have following code in my backing bean:

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;
}

In jsf:

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

and

<p:commandButton value="Save" actionListener="#{contractView.update}" update="growl"/>

As a result I'm getting:

enter image description here

Like you can see this is far from SEVERITY_ERROR. But the most interesting part is when my code is following (adding message outside the catch block):

    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;
    }

then all fine:

enter image description here

How can I set SEVERITY_ERROR level to my message while handling exception?

1

There are 1 best solutions below

0
Igor Gorbunov On

My problem relates with EE container. In case I'm not extended from EJBException they wrapping automatically, therefore block catch doesn't executing. There are two ways to solve my problem:

  1. Extend my custom exception from EJBException
  2. Add @ApplicationException annotation to my class exception