[英]How to get the ID attribute of h:selectBooleanCheckbox in backing bean
[英]JSF 1.1 - How to get the ID attribute of h:selectBooleanCheckbox in backing bean
因此,這是jsf組件:
<h:selectBooleanCheckbox id="cb#{index}" value="backingBean.value" />
這是支持bean java的一部分:
/**
* getValue is a method which checks if a checkbox is selected or not, using the checkbox ID
*/
public boolean getValue() {
//TODO: get the checkbox id
String checkboxID = ??
if (getCheckedIDs().contains(checkboxID)) {
return true;
}
return false;
}
當頁面正在加載復選框時,我想以這種方式檢查是否選中了該復選框。 所以問題是,寫什么而不是?? 獲取調用該方法的復選框的ID? 我只能使用JSF 1.1,這一點非常重要,因此有許多解決方案不適用於該版本。
編輯:正如@Kukeltje正確指出的那樣,主要問題是值表達式不正確。 更改后,以下內容適用。
您不需要“計算”復選框的值(“設置”或“未設置”)。 JSF會簡單地調用backingbean.setValue(x)
( x
為true
或false
),具體取決於該復選框在該時刻(即提交頁面時)處於打開還是關閉狀態。
這是自動發生的,因為您說的是value="#{backingBean.value}"
。
因此,在setValue()
您僅存儲參數,在getValue
,返回存儲的參數。 其余的工作由JSF為您完成。
如果希望默認情況下選中此復選框,則將存儲的值設置為true。
例如:
private boolean storedValue = true; // or false if you want it to be off by default
public boolean getValue() {
return storedValue;
}
public void setValue(boolean value) {
this.storedValue = value;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.