2011-03-03 79 views

回答

8

讓輸入的required屬性檢查複選框的值。

這裏有一個開球例如:

<h:form> 
    <h:dataTable value="#{bean.list}" var="item"> 
     <h:column><h:selectBooleanCheckbox binding="#{checkbox}" /></h:column> 
     <h:column><h:inputText id="input" value="#{item.value}" required="#{checkbox.value == 'true'}" /></h:column> 
     <h:column><h:message for="input" /></h:column> 
    </h:dataTable> 
    <h:commandButton value="submit" action="#{bean.submit}" /> 
</h:form> 
+3

嚴重的是,不管問題,我搜索和有關JSF。到目前爲止,@BalusC的迴應是完美的。尊重你先生。 :-) – 2012-11-21 18:39:20

+0

一個問題:在上面的代碼中:我們不需要關聯複選框的值更改的監聽器來更新inputText的必需屬性? – 2012-11-21 19:53:03

+0

@Mukul。別客氣。不,你不需要更改監聽器等等。 'required'屬性在處理表單提交的請求期間被評估,而不是在顯示錶單的請求期間被評估。答案中的示例按原樣完成。 – BalusC 2012-11-22 03:37:32

相關問題