facesContext.validationFailed返回null

时间:2012-07-24 20:59:11

标签: jsf-2

facesContext.validationFailed是什么原因可能为null? (在有错误的postBack中..) 我不得不求助于一个丑陋的if (#{fn:containsIgnoreCase(facesContext.maximumSeverity,'ERROR')}) showSecurePopup('confirm');,因为facesContext.validationFailed将返回null ..

测试代码是:

<h:form>
   <h:messages />
   <br></br>

   <h:outputText value="Validation failed: #{facesContext.validationFailed}" />
   <br></br>

   <h:outputLabel for="field1" value="Test Field" />
   <br></br>

   <h:inputText required="true" />

   <h:commandButton action="#{contactBacking.submitComment}" value="Submit"
      <f:ajax render="@form" execute="@form" />
   </h:commandButton>
</h:form>

编辑:根据@ BalusC的回答编辑..并截取结果截图:

image

1 个答案:

答案 0 :(得分:0)

FacesContext#isValidationFailed()返回boolean 从不 null。只是摆脱那种无意义的无效检查。

<h:outputText value="Validation failed: #{facesContext.validationFailed}" />