0

I have a bit complex structure. First, I start problems table. Each problem has a subcategory and maincategory and also each subcategory has a main category. Besides, a main category have sub categories and a subcategory have problems.

Then, I tried to list them like below.

I have created a dynamic web form with JSF SelectManyCheckbox. It is the following:

<ui:repeat  var="mainCatvar" value="#{dprEdit.mainCategories}">
    <h:outputText value="#{mainCatvar.mainCatName}" styleClass="mainTitle"/>
        <ui:repeat var="subCategory" value="#{mainCatvar.subCategories}">
        <h:outputText value="#{subCategory.subCatName}" styleClass="title" />
            <p:selectManyCheckbox value="#{dprEdit.selectedProblems[subCategory]}">
                <f:selectItems value="#{subCategory.problems}" var="problem" 
                itemValue="#{problem.problemId}" 
                itemLabel="#{problem.problemName}" />                       
            </p:selectManyCheckbox>
        </ui:repeat>
</ui:repeat>

In the java code,

problems = new ProblemDAO(ConnectionManager.getConnection())
        .getProblems(formId);
        for (int i = 0; i < problems.size(); i++) {
            Problem problem = problems.get(i);
        if (subcat == problem.getSubCat())
            problemIdList = addElement(problemIdList,problem.getProblemId().toString());
        else
            Arrays.fill(problemIdList, null);
            problemIdList = addElement(problemIdList,problem.getProblemId().toString());
            subcat = problem.getSubCat();
            selectedProblems.put(problem.getSubCat(), problemIdList);   
        }

PS: addElement is a function that is written to add an element to the array whose length is already defined.

I suppose, I send the data like below to the xhtml.

(subcat1, [1,2]),(subcat3,[5]) etc...

And the value of dprEdit.selectedProblems[subCategory] is a list.

And I send a list as a value.

So I expect that the problems whose ids are 1,2,5 must be checked but they don't.

Where am I wrong?

JSF 2.2, Mojarra, PrimeFaces and Tomcat 7.x.

Armagan
  • 68
  • 9

0 Answers0