ZZ 5
ZZ 5

Reputation: 1954

FacesMessage is not displayed when being set in an action method with a redirect outcome

Why the code from the first block works and the other one doesn't? It's all about displaying JSF messages

@PostConstruct
public void init() {
    try {
        throw new RuntimeException();
    } catch (RuntimeException e) {
        i18nExceptionHandler.handleException(e);
    }
}

The code above works well - it displays the message.

public String login() {
    try {
       //login actions
    } catch (AuthenticationException e) {
      //this doesn't work
        i18nExceptionHandler.handleException(e);
    }
    return "/pages/loggedin?faces-redirect=true";
}

This code doesn't work - it doesn't display any message and I'm given following error:

WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.

Why it works like that? Shall I use validator or something else on the login method (and the rest as well)?

Upvotes: 1

Views: 2529

Answers (2)

ZZ 5
ZZ 5

Reputation: 1954

Message from the second code block wasn't displayed, because method hasn't got void signature.

Upvotes: 0

Mohan Kanakala
Mohan Kanakala

Reputation: 1160

You need to include h:messages tag in your jsf page. for example,

<h:messages id="messagesID" globalOnly="true" layout="table" />

If you don't have this in your JSF page, the warning message will arise.

Upvotes: 1

Related Questions