<p:message>无法在复合</p:message>中使用

时间:2014-05-21 19:02:15

标签: java jsf-2 primefaces

我使用的是primefaces 5,我有以下形式:

<h:form id="registarVagaForm" prependId="false">
    <p:panel id="dadosGeraisVagaPanel" header="#{label['seccao.registarVaga.dadosGerais']}" toggleable="true" closable="false" toggleSpeed="500" widgetVar="panel">
        <recrutamento:vaga titulo="#{registarVaga.vaga.titulo}" descricao="#{registarVaga.vaga.descricao}" observacoes="#{registarVaga.vaga.observacoes}" competencias="#{registarVaga.competencias}" disabled="false" />
        <f:facet name="footer">
            <div align="right">
               <p:commandButton action="#{registarVaga.registar}" value="#{label['campo.registarVaga.botao.registar']}" ajax="false" />
            </div>
        </f:facet>
    </p:panel>
</h:form>

在复合vaga内,我有以下dataTable tabelaCompetencias

<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" 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:p="http://primefaces.org/ui" xmlns:sec="http://www.springframework.org/security/facelets/tags" xmlns:composite="http://java.sun.com/jsf/composite">
    <composite:interface>
        ...
    </composite:interface>
    <composite:implementation>
        ...
        <p:panelGrid columns="2" styleClass="invisibleGrid" >
            <h:outputLabel value="#{label['seccao.registarVaga.competencias.associadas']}" for="tabelaCompetencias" />
            <p:message for="tabelaCompetencias" />
        </p:panelGrid>
        <p:dataTable id="tabelaCompetencias" var="competencia" value="#{cc.attrs.competencias}" selection="#{registarVaga.competenciasSelecionadas}" rowKey="#{competencia.id}" rows="15" paginator="true" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" paginatorPosition="bottom" style="width:600px;">
            <p:column headerText="#{label['seccao.registarVaga.competencias.descricao']}">
                <h:outputText value="#{competencia.descricao}" />
            </p:column>
            <p:column selectionMode="multiple" style="width:3%;text-align:center"/>
        </p:dataTable>
    </composite:implementation>
</html>

当我提交表单并且我的验证失败时,我尝试将错误消息传递给&#34; tabelaCompetencias&#34;像这样:

final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Error!");
FacesContext.getCurrentInstance().addMessage("tabelaCompetencias", facesMsg); 

在我的其他非复合视图中,它的工作方式就像一个魅力,但如果声明为复合,我的消息就不会显示。另外,如果我使用inputTextrequired="true",则primefaces会正确显示消息。

我做错了什么?任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我为自己找到了解决同样困境的人:

String tabelaCompetenciasId = ComponentUtils.findComponentClientId("tabelaCompetencias");
final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Error!");
FacesContext.getCurrentInstance().addMessage(tabelaCompetenciasId , facesMsg);