사람들이 성공적으로이 작업을 수행 한 jsf에서 다양한 예제를 발견했습니다. 이 예제에서는 사람이 동적 체크 박스 목록을 표시하는 데 사용했습니다.JSF - 응답을 캡처하지 않는 다중 선택 체크 박스
내 확인란을 사용하여 HtmlPanelGrid를 작성한 다음 페이지에 해당 HtmlPanelGrid를 표시하여 약간 다른 작업을 시도하고 있습니다. 체크 박스는 경로를 사용한 것처럼 화면에 나타납니다.
확인란이 선택되었는지 확인하기 위해 값을 캡처하려고하면 문제가 발생합니다. 나는 '응답'배열 값을 'false'로 초기화했다. 체크 박스를 몇 개 선택하여 양식을 제출 한 후 데이터베이스를보고 모든 값을 false로 저장했습니다 ('사실'이 몇 개가 있어야 했음).
코드 조각을 displayForm.xhtml에서 :
<h:form id="form_selection_test">
<!-- Display the prompt -->
<h3>
<h:outputText id="selection_prompt" value="#{testBean.prompt}"></h:outputText>
</h3>
<!-- Display the selection - the type of selection will vary based on misc criteria -->
<h:panelGrid binding="#{myBean.testSelectionGrid}">
</h:panelGrid>
<br/><br/>
<h:commandButton id="selection_form_submit" type="submit" value="Submit!" action="#{myBean.processSelection}"/>
</h:form>
발췌문 myBean.java에서
희망 내 코드 조각 내가 뭘 잘못 식별하는 데 도움이 될 수 있습니다
public HtmlPanelGrid getTestSelectionGrid()
{
myGrid = new HtmlPanelGrid();
myGrid.setColumns(2);
List children = myGrid.getChildren();
// get application from faces context
FacesContext facesInstance = FacesContext.getCurrentInstance();
Application app = facesInstance.getApplication();
ExpressionFactory expFactory = app.getExpressionFactory();
int numChoices=choices.size(); //choices is the array containing the values for each selection option
responses.clear(); //clear any old values out of the array;
//initialize the response array (also a part of myBean) - this is supposed to capture the items the user selects
for(int initAns=0;initAns<numChoices;initAns++)
{
responses.add("false");
}
/*
*
* Other selection types (non-checkbox)
* These other selection types seem to work fine with capturing user responses
*
*/
if (selectionToDisplay =="multipleChoiceCheckbox")
{
HtmlSelectManyCheckbox checkboxPanel = new HtmlSelectManyCheckbox();
checkboxPanel.setLayout("pageDirection");
checkboxPanel.setValue("#{myBean.responses}");
Map<Object,Object> checkChoiceList = new HashMap<Object,Object>();
for (int i=0;i<numChoices;i++)
{
Object choiceValueExpression= expFactory.createValueExpression(facesInstance.getELContext(),"#{question.responses["+i+"]}",String.class).getValue(facesInstance.getELContext());
checkChoiceList.put("TEST["+i+"]"+choices.get(i),"true");//choiceValueExpression);
}
UISelectItems checkboxList = new UISelectItems();
checkboxList.setValue(checkChoiceList);
checkboxPanel.getChildren().add(checkboxList);
children.add(checkboxPanel);
}//end of if that checks if we're supposed to display MultipleChoiceCheckbox
return myGrid;
}
나는 모든 종류의 순열 연주를 해왔지만, 지금까지 내가 본 것 중에서 가장 가깝다. 지금 적어도 체크 박스 그룹이 내 'respnoses'배열과 적절히 연관되어있는 것처럼 보입니다. 그러나 각 개별 확인란의 값을 해당 배열 요소에 캡처 할 수는 없습니다.
어디에서 보거나 시작할 수있는 아이디어가 있습니까?
미리 감사드립니다. 대신 JSF를 댄다
클리프 당신이 빈에서 동적으로 UIInput
또는 UICommand
구성 요소를 만들 때마다