我在 JBoss EAP 6.0 上有一个 JSF 2.1 + RichFaces 4.0 webapp。我无法使用FacesMessage
. 我正在使用添加一条消息addMessage()
。但是,该消息没有显示<rich:messages>
在我的控制台中和我得到的控制台中:
INFO [javax.enterprise.resource.webcontainer.jsf.renderkit] (http-localhost/127.0.0.1:8888-3) 警告:FacesMessage(s) 已入队,但可能尚未显示。sourceId=null[severity=(ERROR 2), summary=(mobile no 应该大于 10 位), detail=()]。
看法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:composition>
<h:head/>
<link href="../../css/styles.css" rel="stylesheet" type="text/css" />
<h:form id="personform12" >
<h:panelGrid id="test2343" width="80%">
<rich:messages id="messages" globalOnly="true" errorClass="globalError" showSummary="true" showDetail="false"></rich:messages>
</h:panelGrid>
<h:panelGrid border="0" columns="3" width="90%" cellpadding="0" cellspacing="1" >
<h:panelGroup styleClass="alignmentRight">
<h:outputText value="#{bundle['id']}" />
</h:panelGroup>
<h:inputText id="id" value="#{personBean.pdto.id}" required="true">
</h:inputText>
<rich:message styleClass="error" for="id" />
<h:panelGroup>
<h:outputText value="#{bundle['name']}" />
</h:panelGroup>
<h:inputText id="name" value="#{personBean.pdto.name}" required="true"/>
<rich:message styleClass="error" for="name" />
<h:panelGroup styleClass="alignmentRight">
<h:outputText value="city" />
</h:panelGroup>
<h:inputText id="city" value="#{personBean.pdto.city}" required="true"/>
<rich:message styleClass="error" for="city" />
<h:panelGroup styleClass="alignmentRight">
<h:outputText value="state" />
</h:panelGroup>
<h:inputText id="state" value="#{personBean.pdto.state}" required="true"/>
<rich:message styleClass="error" for="state" />
<h:panelGroup styleClass="alignmentRight">
<h:outputText value="mobile" />
</h:panelGroup>
<h:inputText id="mobile" value="#{personBean.pdto.mobile}" required="true">
</h:inputText>
<rich:message styleClass="error" for="mobile" />
<h:panelGroup styleClass="alignmentRight">
<h:outputText value="DOB" />
</h:panelGroup>
<rich:calendar style="height:25px" inputStyle="width:203px" required="true"
showWeeksBar="false"
boundaryDatesMode="scroll"
id="dob" value="#{personBean.pdto.dob}"
datePattern="dd/MM/yyyy" cellWidth="24px" cellHeight="22px" />
<rich:message styleClass="error" for="dob" />
</h:panelGrid>
<br/><br/>
<h:commandButton id="commandSubmit" value="Submit" action="#{personBean.save}"></h:commandButton>
</h:form>
</ui:composition>
</html>
模型:
public class PersonJSFBean {
private static final Logger log = Logger.getLogger(PersonJSFBean.class);
private PersonDTO pdto;
private PersonManager personManager;
public String save(){
String str = null;
try {
if(pdto.getMobile().length()<10) {
System.out.println("inside the mobile no>>>>>>>>>>>"+pdto.getMobile());
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "mobile no should be greater than 10 degits ", null);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}
} catch (Exception e) {
System.out.println("Error occured>>>>>>>>>>>");
e.printStackTrace();
}
return str;
}
// ...
}