I have a <h:selectBooleanCheckbox> tag that I use to present the user with a
"Select All" function that allows multiple checkboxes to all be checked.
The tag uses a valueChangedListener to loop through a List and set a
property on all the objects in the List. The list is used by a dataTable
that presents to the user all the previously imported documents that are
contained in the List.
I've determined that the valueChangeListener method is working correctly by
writing debug statements out while looping through the objects in the list
but after the valueChangeListener executes the page does not reflect the
property changes on the objects in the list. The data table does not update
the value of the checkboxes.
The bean (historyBean) is session scoped and has an init method that gets
the list of previously imported documents:
protected void init ()
{
UserBean ub = ( UserBean ) FacesUtils.getManagedBean ( "userBean" );
if ( ub != null )
{
User u = ub.getUser ();
if ( u != null )
{
this.imported = this.serviceLocator.getDocumentService ().
getImportedDocumentsForUser ( u );
}
...
The selectBooleanCheckbox Tag looks like this:
<h:selectBooleanCheckbox value="#{historyBean.allSelected}"
valueChangeListener="#{historyBean.selectAllChanged}" onchange="submit()"/>
The valueChangeListener looks like this (pardon the sloppy code, haven't
finalized this code yet):
public void selectAllChanged ( ValueChangeEvent event )
{
List newList = new ArrayList();
Boolean newValue = (Boolean) event.getNewValue();
int size = this.imported.size ();
if ( !newValue.booleanValue() )
{
for ( int x = 0; x < size; x++ )
{
Document doc = ( Document )this.imported.get ( x );
doc.setSelected ( false );
newList.add ( doc );
}
}
else
{
for ( int x = 0; x < size; x++ )
{
Document doc = ( Document )this.imported.get ( x );
doc.setSelected ( true );
newList.add ( doc );
}
}
this.imported = newList;
}
Any help would be appreciated. One more thing, the property that is being
set (selected) isn't a database field, not sure that would make a difference
but I thought I'd mention it just to see.
-Mark