Working on a jsf application someone else wrote I must be missing something very basic. I stripped it down to this, which is not working:
page.jsp
:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<!doctype html>
<html>
<body>
<f:view>
<h:messages id="error" globalOnly="true"/>
<h:outputText value="#{testBean.msg}"/>
</f:view>
</body>
</html>
testBean.java
:
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class testBean {
public String getMsg() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "getMsg"), null));
return "getMsg";
}
}
That code does not display the error message generated in testBean#getMsg
. If I move the <h:messages>
to after the <h:outputText>
line, the message is displayed. Why is that? Is this supposed to work?