-1

I am trying to check all the checkboxes using Jsf but it is not able to checking.I have written code like this....If i select a checkbox in the header section all the checkboxes need to be selected.

        <h:selectBooleanCheckbox id="c1" value="#{user.check}"></h:selectBooleanCheckbox>
        <h:outputText value="name">name</h:outputText>
        <h:outputText value="age">Age</h:outputText>

        <h:selectBooleanCheckbox id="c2"></h:selectBooleanCheckbox>
        <h:outputText value="A">A</h:outputText>
        <h:outputText value="12">12</h:outputText>

        <h:selectBooleanCheckbox id="c3"></h:selectBooleanCheckbox>
        <h:outputText value="B">B</h:outputText>
        <h:outputText value="14">14</h:outputText>

        <h:selectBooleanCheckbox id="c4"></h:selectBooleanCheckbox>
        <h:outputText value="C">C</h:outputText>
        <h:outputText value="16">16</h:outputText>

        <h:selectBooleanCheckbox id="c5"></h:selectBooleanCheckbox>
        <h:outputText value="D">D</h:outputText>
        <h:outputText value="18">18</h:outputText>

and my mangedbean is like this

@ManagedBean(name="user") public class Userbean {

public boolean check;

public boolean isCheck() {
    return true;
}

public void setCheck(boolean check) {
    this.check = check;
}

}

I dont know how to write logic for that I am trying this...can help

ratnaraj
  • 1
  • 5

2 Answers2

-1

Jsp

<input type="checkbox" id="selecctall"/>Select All</th>
<input type="checkbox" class="checkbox1" id="checkbox" name="checkbox1" value="${al.id}"/>


$(document).ready(function() {
        $('#selecctall').click(function(event) {  //on click 
            if(this.checked) { // check select status
                $('.checkbox1').each(function() { //loop through each checkbox
                    this.checked = true;  //select all checkboxes with class "checkbox1"               
                });
            }else{
                $('.checkbox1').each(function() { //loop through each checkbox
                    this.checked = false; //deselect all checkboxes with class "checkbox1"                       
                });         
            }
        });

    });
-1
jsf page
<h:column>
<f:facet name="header">
<h:selectBooleanCheckbox id="g1" onclick="selectall(sel)"></h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="g2"></h:selectBooleanCheckbox>
</h:column>


and javascript

<script type="text/javascript">
    checked=false;
    function selectall(sel)
    {

    var sele=document.getElementById('sel');
    if(checked==false)
        {
         checked=true;
        }
    else
        {
        checked=false;
        }
    for(var i=0;i!=sele.elements[i];i++)
        {
        sele.elements[i].checked=checked;
        }

    }
</script>
ratnaraj
  • 1
  • 5