I would like to have different messages on different message components, but unfortunately message always display on both message components.
TestFaces.java
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@javax.enterprise.context.RequestScoped
@javax.inject.Named
public class TestFaces implements java.io.Serializable {
static final long serialVersionUID = 1L;
static final Logger logger = LogManager.getLogger();
public String callMsg001() {
FacesContext.getCurrentInstance().addMessage("msg001",
new FacesMessage(FacesMessage.SEVERITY_INFO, "This is msg001", null));
return null;
}
public String callMsg002() {
FacesContext.getCurrentInstance().addMessage("msg002",
new FacesMessage(FacesMessage.SEVERITY_INFO, "This is msg002", null));
return null;
}
}
index.html
<!DOCTYPE HTML>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Index</title>
</h:head>
<h:body>
<h:form>
msg001: <h:messages id="msg001" style="msg001" />
msg002: <h:messages id="msg002" style="msg002"/>
<h:commandButton
value="Trigger msg001"
action="${testFaces.callMsg001()}">
</h:commandButton>
<h:commandButton
value="Trigger msg002"
action="${testFaces.callMsg002()}">
</h:commandButton>
</h:form>
</h:body>
</html>
I would like to have different messages on different message components.