h:消息不显示JSF消息

时间:2014-09-12 17:33:01

标签: jsf richfaces

在我的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>

这是我的Managed 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标记。 验证器是不可能的,因为将从DB传递结果的方法在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? Managed Bean中有什么问题吗?

addMessage("loginFormId:loginId", message)

2 个答案:

答案 0 :(得分:0)

将id插入h:panelGrid,即

<h:panelGrid columns="3" id="grid">

然后在java代码中试试这个

FacesContext.getCurrentInstance().addMessage("loginFormId:grid:loginId", message );

如果有帮助,请告诉我

答案 1 :(得分:0)

FacesMessage由摘要和详细信息组成,rich:message默认显示详细信息。这是你要离开的那个,所以没有什么可以展示的。填写详细信息或设置@showSummary =&#34; true&#34;

相关问题