H:消息不显示JSF消息
以我JSF应用,这里是我的形式的一部分的简化版本:H:消息不显示JSF消息
<h:form id="loginFormId">
<h:panelGrid columns="3">
<h:outputText value="Login :" />
<h:inputText label="Login" id="loginId" />
<rich:message for="loginId" ajaxRendered="true"/>
<f:facet name="footer">
<a4j:commandButton value="OK" action="#{authentifierUtilisateurBean.authentifierUtilisateur}">
<f:ajax execute="@form" render="@form" />
</a4j:commandButton>
</f:facet>
</h:panelGrid>
</h:form>
这是我的管Bean方法authentifierUtilisateur()的简化版本:
public String authentifierUtilisateur() {
try {
utilisateurEnBase = utilisateurDao.chercherParLogin(utilisateur.getLogin());
}
...
if (utilisateurEnBase == ....) {
message = new FacesMessage(FacesMessage.SEVERITY_ERROR, bundle.getString("authentifier.utilisateur.login.inconnu"),"");
FacesContext.getCurrentInstance().addMessage("loginFormId:loginId", message);
}
我想根据authentifierUtilisateur()方法中发生的事情,将一个错误分配给与h:inputText相关的rich:message标记。 验证器是不可能的,因为将从数据库传递结果的方法在authentifierUtilisateur()方法中运行。
当我尝试上面的代码时,页面不会在h:inputText前面显示消息。
如果我的形式插入,代码
<rich:messages />
上面的按钮如下(以s消息):
<f:facet name="footer">
<rich:messages />
<a4j:commandButton value="OK" action="#{authentifierUtilisateurBean.authentifierUtilisateur}">
<f:ajax execute="@form" render="@form" />
</a4j:commandButton>
</f:facet>
然后我可以看到消息所以我确信服务器将正确的消息发送给客户端。 那么为什么客户端不在h:inputText前面显示h:message? 托管Bean有什么问题吗?
addMessage("loginFormId:loginId", message)
一个FacesMessage
由摘要和详细信息,rich:message
将默认显示详细信息。那是你要离开的那个人,所以没什么可显示的。要么填写的细节或设置@ showSummary =“true”
插入一个ID,H:panelGrid的即
<h:panelGrid columns="3" id="grid">
然后在Java代码中尝试这个
FacesContext.getCurrentInstance().addMessage("loginFormId:grid:loginId", message);
让我知道,如果这有助于
谢谢你的帮助,但这不是我的错误的原因。马凯尔的回答指出了我的错误。 – Philippe 2014-09-17 14:21:14
非常感谢。你指出我的错误。 – Philippe 2014-09-17 14:21:44