2011-04-05 3 views
1

I했습니다 내 사용자 편집 화면에서 다음 코드JSF의 체크 박스 목록으로 데이터를 바인딩하는 방법은 무엇입니까?

<h:selectManyCheckbox id="selectedGroups" value="#{usersController.selectedGroups}"> 
       <f:selectItems value="#{usersController.groupsList}" var="item" itemLabel="#{item.groupname}" itemValue="#{item.groupid}" /> 
      </h:selectManyCheckbox> 

내가 모든 그룹과 사용자 그룹 목록을했습니다, 그리고 사용자를 사용할 수있는 그룹과 selectedGroups 목록을했습니다. 그러나 편집 화면에서는 기본적으로 선택되어 표시되지 않습니다. 내가 뭘 놓치고 있니? 선택한 여러 체크 상자를 바인딩하는 올바른 방법이 아닌가요?

답변

1

groupsList 아이템 값 equals()selectedGroups 방법은 적어도 하나 개의 항목을 리턴 true 때만 미리 선택한다.

groupidLong이라고 가정하면, 다음 selectedGroups은 값을 포함하는 미리 선택된 List<Long>가되도록 복귀한다. 요청 범위 빈을 위해 완벽하게 작동하는 코드에 따라

0

...

XHML 코드 ....

<h:selectManyCheckbox binding="#{Page1.chk_1}"> 
     <f:selectItem binding="#{Page1.chk_1_options}"/> 
</h:selectManyCheckbox> 

자바 코드 ....

HtmlSelectManyCheckbox chk_1 = new HtmlSelectManyCheckbox(); 
UISelectItems chk_1_options = new UISelectItems(); 

public HtmlSelectManyCheckbox getChk_1() { 
    return chk_1; 
} 

public void setChk_1(HtmlSelectManyCheckbox chk_1) { 
    this.chk_1 = chk_1; 
} 

public UISelectItems getChk_1_options() { 
    if (chk_1_options.getValue() == null) { 
     List<SelectItem> lst_chk_options = new ArrayList<SelectItem>(); 
     lst_chk_options.add(new SelectItem(1, "Label1")); 
     lst_chk_options.add(new SelectItem(2, "Label2")); 
     chk_1_options.setValue(lst_chk_options); 
    } 
    return chk_1_options; 
} 

public void setChk_1_options(UISelectItems chk_1_options) { 
    this.chk_1_options = chk_1_options; 
} 

당신이 원하는 경우 세션 범위의 바인딩 요소가 어떤 경우에 문제를 발생시키기 때문에 세션 범위가 다음으로 응답합니다.

관련 문제