I have a problem with the h:messages tag in JSF that simply does not show any messages. In the Glassfish log are no errors when I click the button.
The setup is as follows:
test.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:j="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h:messages globalOnly="true"/>
<h:form id="loginform">
<p:commandButton id="testButton" value="Test"
action="#{loginSessionBean.test()}" />
</h:form>
</h:body>
</html>
With The SessionScopedBean:
@ManagedBean
@SessionScoped
public class LoginSessionBean implements Serializable {
private static final long serialVersionUID = 1L;
...
public String test(){
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Test!", null));
return "";
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…