2011-01-12 82 views
1

我想驗證一個基於選擇CheckBox的inputText框,如下所示。 < <h:inputText required="#{param[facesContext.externalContext.response.namespace'form:checkBoxId']}"> >JSF複合EL表達式

問題就像你看到的,組件ID是動態的,我應該能夠在EL表達式中使用facesContext.externalContext.response.namespace。有沒有解決方案,感謝任何建議。

謝謝。

回答

0

只需將UIComponent綁定到頁面範圍的屬性並訪問它的getValue()方法即可。

<h:selectBooleanCheckbox binding="#{checkbox}" /> 
<h:inputText required="#{not empty checkbox.value and checkbox.value}" /> 

至於動態性,你也可以通過給它一個固定的ID來解決問題。

<h:form id="form"> 
    <h:selectBooleanCheckbox id="checkbox" /> 
    <h:inputText required="#{not empty param['form:checkbox'] and param['form:checkbox']}" /> 
</h:form> 

然而,只有當它變得冗長時纔是醜陋的。

+0

感謝BalusC,第一個解決方案對我來說非常完美。 – 2011-01-12 18:11:21