2013-12-23 38 views
0

我有一個jsf中的xhtm和一個模態。模態JSF中的錯誤消息不起作用

在這種模式中,我有一個字段,我試圖驗證並返回一個錯誤。

我的代碼:

模態:

<rich:popupPanel id="cancelssi" modal="true" width="500" height="280" zindex="2" domElementAttachment="form" show="#{demandasMB.showCancelar}" showWhenRendered="#{demandasMB.showCancelar}" > 
    ... 


<h:panelGroup layout="block" class="area-input-100" id="idmotivocancelamentopanel"> 
       <h:panelGroup class="label-campo">Justificativa de cancelamento:</h:panelGroup>  
       <h:inputTextarea styleClass="textarea-form-2-linhas" id="idmotivocancelamento" value="#{demandasMB.demandas.cnmmotivocancelamento}" maxlength="255"/> 
       <h:message for="idmotivocancelamento" />          
      </h:panelGroup> 

      <h:panelGroup layout="block" class="clear"/> 

      <h:panelGroup layout="block" styleClass="alinhaBotao"> 
       <h:commandButton value="Cancelar"> 
        <f:ajax render="idmotivocancelamento idmotivocancelamentopanel" 
           event="click" 
           listener="#{demandasMB.preCancelar()}" 
           execute="@form" 
           /> 
       </h:commandButton>   
       <h:commandButton value="Fechar"/>   
      </h:panelGroup> 
    </rich:popupPanel> 
在我的MB

我:

public void preCancelar(){ 

    if(StringUtils.isBlank(demandas.getCnmmotivocancelamento())){ 

     FacesMessage fm = new FacesMessage("Favor preencher"); 
     FacesContext.getCurrentInstance().addMessage("idmotivocancelamento",fm); 

    }else{ 
     showConfirmacaoCancelar = true; 
     showCancelar = false; 
    } 
} 

I'm建設的FacesMessage但doesn't出現在我的模式。

我做錯了什麼?

感謝

回答

1

您需要AJAX的更新idmotivocancelamentopanel反映FacesMessages您要添加。

另一種方法是使用<rich:message/>。使用ajaxRendered="true"屬性將允許消息組件在ajax請求上自動更新。所以你會改爲:

<rich:message for="idmotivocancelamento" ajaxRendered="true"/>