I want to display error messages when the user first requested the page. The error is set in the post construct method of the request scoped managed bean like the following:
@RequestScoped
public class MyBean {
private String name;
@PostConstruct
public void init() {
// some validations here
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "You have no credit!");
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, message);
context.renderResponse();
}
public String getName() {
return name;
}
}
and then in my JSF page:
<!-- I'm expecting the error you have no credit will be displayed here -->
<h:messages />
<h:form>
<h:inputText value="#{myBean.name}" />
</h:form>
When run in development stage, the JSF complaints that this is an unhandled messages:
"Project Stage[Development]: Unhandled Messages - You have no credit!"
Can you help me?