當提交按鈕確實被按下時,讓required
屬性評估true
。然而
問題的答案取決於你如何提交按鈕的方式執行它的邏輯(標準,f:ajax
,ICEfaces的,等等)。但基本上可以歸結爲,您可以檢查請求參數映射中的請求參數,該參數表明所需的提交按鈕已被按下。
例如,如果它是一個標準的命令按鈕:
<h:form id="form">
...
<h:commandButton id="submit" value="Submit" action="#{bean.submit}" />
</h:form>
然後,你可以通過檢查檢查,如果按鈕的客戶端ID出現在請求參數映射:
<c:set var="submitButtonPressed" value="#{not empty param['form:submit']}" />
...
<h:inputText ... required="#{submitButtonPressed}" />
<h:inputText ... required="#{submitButtonPressed}" />
<h:inputText ... required="#{submitButtonPressed}" />
或者,如果它是一個<f:ajax>
按鈕:
<h:form id="form">
...
<h:commandButton id="submit" value="Submit" action="#{bean.submit}">
<f:ajax execute="@form" ... />
</h:commandButton>
</h:form>
然後,你可以通過檢查檢查荷蘭國際集團如果javax.faces.source
參數等於按鈕的客戶端ID:
<c:set var="submitButtonPressed" value="#{param['javax.faces.source'] == 'form:submit'}" />
...
<h:inputText ... required="#{submitButtonPressed}" />
<h:inputText ... required="#{submitButtonPressed}" />
<h:inputText ... required="#{submitButtonPressed}" />
你甚至可以結合兩種:
<c:set var="submitButtonPressed" value="#{not empty param['form:submit'] or param['javax.faces.source'] == 'form:submit'}" />
...
<h:inputText ... required="#{submitButtonPressed}" />
<h:inputText ... required="#{submitButtonPressed}" />
<h:inputText ... required="#{submitButtonPressed}" />