You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Samb Green <p....@yahoo.fr> on 2009/06/13 13:17:32 UTC

wrong rows with selectBooleanCheckbox and datatable

Hi all,

 I have a problem with  selectBooleanCheckbox in a datatable. I want to check a number of rows and delete them in the backing bean. However the rows marked as checked in the backing bean are different than those checked on the UI. However the number of rows checked is the same, it just checks wrong rows in the backing bean. Can anybody help please. I googled and seached the mailiong archiove but did not find any similar problem. Here is the code source: (I am using myfaces 1.1.5, tomahawk 1.1.7, jboss 4.0.3SP1)

Th JSP:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@ include  file="/jsps/inc/taglibs.inc"%>   
<html>
<body>
<f:view>
    <h:form styleClass="inputForm">
               <t:dataTable id="precptT" renderedIfEmpty="false"            
                 columnClasses="column-left,column-left,column-left,column-left,column-left,column-right"
                 rowClasses="row-grey,row-none" 
                 styleClass="table"
                 value="#{PrecBean.precomptes}"             
                 var="precompte">
             
            <h:column>
                <h:selectBooleanCheckbox id="aPrecpt" value="#{precompte.checked}"/> 
            </h:column>

            <h:column>
                <f:facet name="header">        
                    <h:outputText value="No Mat" /> 
                </f:facet>
                <h:outputText value="#{precompte.noMat}" />
            </h:column>
            <h:column>
                <f:facet name="header">        
                    <h:outputText value="Name" /> 
                </f:facet>
                <h:outputText value="#{precompte.name}" />
            </h:column>
            
            <h:column>
                <f:facet name="header">
                    <h:outputText value="Amount" />
                </f:facet>
                <h:outputText id="credLEC" value="#{precompte.amount}">
                    <f:convertNumber pattern="##,###" />
                </h:outputText>
            </h:column>             
          </t:dataTable>

           <br>  
   
           <h:commandButton id="ajout" 
               rendered="#{DemORIBean.nbPrecomptes != 0}"
               action="#{PrecBean.deleteSelections}"
               value="-"/>
    </h:form>
</f:view>
</body>
</html>


The backing bean:


public class PrecompteBean implements Serializable
{
    private static final long serialVersionUID = -1;
    private List<Precompte> precomptes;

       public List<Precompte> getPrecomptes() 
       {
            // Get data from database
            return precomptes;
       }

       public void setPrecomptes(List<Precompte>  precomptes) 
       {
            this.precomptes = precomptes;
       }

       // Method to delete the selected row. 
    public String deleteSelections()
    {        
        for( Precompte prcpt: this.precomptes)
        {
            if( prcpt.isChecked())
            {
                // ... delete 
            }
        }   
        return null;
    }
}


The Precompte value object to hold data from each row of the database table

public class Precompte implements Comparable, Serializable
{
         private static final long serialVersionUID = -1L;
         private boolean checked;
         // ... declarations of other properties


       /**
        * @return Returns the checked.
        */
      public boolean isChecked()
      {
           return this.checked;
      }

    /**
     * @param checked The checked to set.
     */
    public void setChecked( boolean checked)
    {
        this.checked = checked;
    }

     // .... implementation of other getters and setters
}


      

Re: wrong rows with selectBooleanCheckbox and datatable

Posted by Anton Gavazuk <an...@gmail.com>.
Use DataModel instead of direct List.

2009/6/13 Samb Green <p....@yahoo.fr>

> Hi all,
>
>  I have a problem with  selectBooleanCheckbox in a datatable. I want to
> check a number of rows and delete them in the backing bean. However the rows
> marked as checked in the backing bean are different than those checked on
> the UI. However the number of rows checked is the same, it just checks wrong
> rows in the backing bean. Can anybody help please. I googled and seached the
> mailiong archiove but did not find any similar problem. Here is the code
> source: (I am using myfaces 1.1.5, tomahawk 1.1.7, jboss 4.0.3SP1)
>
> Th JSP:
>
> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
> <%@ include  file="/jsps/inc/taglibs.inc"%>
> <html>
> <body>
> <f:view>
>     <h:form styleClass="inputForm">
>                <t:dataTable id="precptT" renderedIfEmpty="false"
>
>
> columnClasses="column-left,column-left,column-left,column-left,column-left,column-right"
>                  rowClasses="row-grey,row-none"
>                  styleClass="table"
>                  value="#{PrecBean.precomptes}"
>                  var="precompte">
>
>             <h:column>
>                 <h:selectBooleanCheckbox id="aPrecpt"
> value="#{precompte.checked}"/>
>             </h:column>
>
>             <h:column>
>                 <f:facet name="header">
>                     <h:outputText value="No Mat" />
>                 </f:facet>
>                 <h:outputText value="#{precompte.noMat}" />
>             </h:column>
>             <h:column>
>                 <f:facet name="header">
>                     <h:outputText value="Name" />
>                 </f:facet>
>                 <h:outputText value="#{precompte.name}" />
>             </h:column>
>
>             <h:column>
>                 <f:facet name="header">
>                     <h:outputText value="Amount" />
>                 </f:facet>
>                 <h:outputText id="credLEC" value="#{precompte.amount}">
>                     <f:convertNumber pattern="##,###" />
>                 </h:outputText>
>             </h:column>
>           </t:dataTable>
>
>            <br>
>
>            <h:commandButton id="ajout"
>                rendered="#{DemORIBean.nbPrecomptes != 0}"
>                action="#{PrecBean.deleteSelections}"
>                value="-"/>
>     </h:form>
> </f:view>
> </body>
> </html>
>
>
> The backing bean:
>
>
> public class PrecompteBean implements Serializable
> {
>     private static final long serialVersionUID = -1;
>     private List<Precompte> precomptes;
>
>        public List<Precompte> getPrecomptes()
>        {
>             // Get data from database
>             return precomptes;
>        }
>
>        public void setPrecomptes(List<Precompte>  precomptes)
>        {
>             this.precomptes = precomptes;
>        }
>
>        // Method to delete the selected row.
>     public String deleteSelections()
>     {
>         for( Precompte prcpt: this.precomptes)
>         {
>             if( prcpt.isChecked())
>             {
>                 // ... delete
>             }
>         }
>         return null;
>     }
> }
>
>
> The Precompte value object to hold data from each row of the database table
>
> public class Precompte implements Comparable, Serializable
> {
>          private static final long serialVersionUID = -1L;
>          private boolean checked;
>          // ... declarations of other properties
>
>
>        /**
>         * @return Returns the checked.
>         */
>       public boolean isChecked()
>       {
>            return this.checked;
>       }
>
>     /**
>      * @param checked The checked to set.
>      */
>     public void setChecked( boolean checked)
>     {
>         this.checked = checked;
>     }
>
>      // .... implementation of other getters and setters
> }
>
>
>
>
>
>
>
>