簡體   English   中英

如何在后備bean中獲取h:selectBooleanCheckbox的ID屬性

[英]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,這一點非常重要,因此有許多解決方案不適用於該版本。

另一個非常重要的事情是,我不能像下面這樣在后備bean中使用setter / getter: https : //stackoverflow.com/a/48006066/9158590 ,因為我需要在選中或取消選中復選框后立即存儲它的值,不僅在提交之后。 檢查后我已經解決了在后備bean中的存儲問題,加載頁面時只需要發送true或false即可。
這是因為我使用頁面導航,例如,當我在第1頁中選中一個框,然后轉到另一頁然后再返回時,不再選擇該框(僅在后備bean中)。

   FacesContext context = FacesContext.getCurrentInstance();
   UIComponent comp = context.getViewRoot().findComponent("Parent Element 
   id of HtmlSelectBooleanCheckbox ");
   for(UIComponent c : comp.getChildren())
    if(c instanceof HtmlSelectBooleanCheckbox)
   {
   // do something
   }

來到您的問題:變量“#{backingBean.value}”的值為true,則將選中該復選框

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM