cancel
Showing results for 
Search instead for 
Did you mean: 

general JSF question (table with checkbox)

friedman30
Champ in-the-making
Champ in-the-making
I am trying to modify one of the pages so that the table within it will have a checkbox and a link in every row.

I've built the table, and everything seems to work fine besides one thing - i can't get the checkbox to be selected via the java code…

:arrow: i need to check every row of the table's model and for the desired rows i need to select the checkbox…

I've tried using phase listeners - i get the right model, get the row, get the checkbox from the row, set "selected" to "true", but still - the checkbox is rendered as unchecked….

any ideas????
:roll:
thanks.

Dror
6 REPLIES 6

friedman30
Champ in-the-making
Champ in-the-making
anyone???
i am really stuck here…

:?

dhalupa
Champ on-the-rise
Champ on-the-rise
Posting some code would be helpfull..

friedman30
Champ in-the-making
Champ in-the-making
thanks dhalupa.

this is the relevant code:

[MyBean = the backing bean for the page
childRefs = a collection of references i want to present in the table]
<h:dataTable id="myTable" border="0" binding="#{MyBean.myTable}" value="#{MyBean.childRefs}" var="line">
   <h:column>
        <h:selectBooleanCheckbox id="myCheckbox" immediate="true"/>
   </h:column>
   <h:column>
         <h:commandLink id="cmd-link" action="#{MyBean.getChildrenForNode}" immediate="true">
               <h:outputText id="output-text" value="#{line.QName.localName}"/>
         </h:commandLink>
   </h:column>   
</h:dataTable>

the page shows some data, and every row is a link to the next level of data (the functionlity is similar to navigating through folders - which means - i need to change the model of the table)
when i navigate (as i metioned, i can navigate in and out) i need to show every checkbox that was selected as checked, even when i return to it after i navigated elsewhere…

this is what i do when i navigate to the next level (or back to a level i already visited):

[checkedValues = a collection of the recently checked values (i add every value that is checked to this collection)]
if(myTable!= null)
      {
         for (int i=0; i < myTable.getRowCount(); i++)
         {   
            myTable.setRowIndex(i);
            if(checkedValues.contains(((ChildAssociationRef)myTable.getRowData()).getChildRef()))
            {
               UISelectBoolean box =  (UISelectBoolean)myTable.findComponent("categoryCheckbox");
               box.setSelected(true);
               box.setValue(true);
               box.saveState(context);

            }
         }
      }

but still - after setting the checkbox for all the desired rows, the table is rendered and non of the checkboxes is selected….

:evil:

thanks,

Dror

dhalupa
Champ on-the-rise
Champ on-the-rise
Uf, this is completely wrong, there is only one instance of uiselectboolean component in the component tree and datatable during rendering of children is encoding this component once per each row. Therefore you can not update the value of your component like this. You have to bound the value property of selectbox component to something from your datamodel like ${line.selected}.

friedman30
Champ in-the-making
Champ in-the-making
thanks dhalupa!!!

i did exactly that. now it is working  :wink:

ebo
Champ in-the-making
Champ in-the-making
Yes that is the correct approach as Craig states here

http://forum.java.sun.com/thread.jspa?threadID=486654&messageID=2819434

I too can get it to work fine in a data table. BUT, as soon as I try and do this in an alfresco rich list I get a "base is null" validation error. Any ideas?

<a:richList viewMode="details" pageSize="20" 

var="promotion"

        <a:column primary="true">
            <f:facet name="header">
                <a:outputText value="Bulk" styleClass="header" />
            </f:facet>
            <h:selectBooleanCheckbox title="bulkUpdates" value="#{promotion.selected}"></h:selectBooleanCheckbox>
      </a:column>
</a:richList>