What do you mean by loosing state, are they having incorrect state or no state 
at all ?

It seems to me that, each of the check boxes is displayed twice and later check 
box's status will be stored in your managed bean. I think after submit you are 
seeing the same state on the two sets of check boxes.

-Srikanth

-----Original Message-----
From: Jan Bols [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 02, 2005 7:02 AM
To: [email protected]
Subject: <x:checkbox> looses state when inside dataTable


I have the following form:

<h:form>        
        <x:dataTable var="data" value="#{test.dataModel2}">
                <x:selectManyCheckbox id="items" layout="spread">
                        <f:selectItems value="#{test.items2}"/>
                </x:selectManyCheckbox>
                
                <h:column>
                        <x:checkbox for="items" 
index="#{test.dataModel2.rowIndex}"/>
                </h:column>
        </x:dataTable>
        
        <x:selectManyCheckbox>
                <f:selectItems value="#{test.items2}"/>
        </x:selectManyCheckbox>

        <h:commandButton value="Submit" />
</h:form>

As you can see it contains 2 times the same list of checkboxes and a  
submit button. The first list of checkboxes is nested inside a dataTable.  
This way I have some control over where the <x:checkbox> items must be  
placed. The other list of checkboxes is just a plain selectManyCheckbox.

The problem is that the first list of checkboxes loses state after the  
submit, while the second one doesn't (as is the normal behaviour). In  
other words the first list doesn't work.

The managed bean test is hooked to this class:

public class Test {
        private Collection items2;
        private DataModel dataModel2;
        
        public Test() {
                items2 = new ArrayList(3);
                items2.add(new SelectItem("200", "Duke's Quarterly", ""));
                items2.add(new SelectItem("202", "Duke's Diet and Exercise 
Journal",  
""));
                items2.add(new SelectItem("201", "Innovator's Almanac", ""));

                dataModel2 = new ListDataModel((List) items2);
        }
        public DataModel getDataModel2() {return dataModel2;}
        public void setDataModel2(DataModel dataModel2) {this.dataModel2 =  
dataModel2;}
        public Collection getItems2() {return items2;}
        public void setItems2(Collection items2) {this.items2 = items2;}
}

What am I doing wrong here? It seems really difficult to render checkboxes  
inside dataTables.

Jan

Reply via email to