0

I am new to jquery. My project invovles primefaces 4.0, jsf 2.1 (xhtml).

I have a select all boolean checkbox, and a selectmanycheckbox which is filled using a list retreived from the server side.

<p:tab title="Service Status" >
    <p:selectBooleanCheckbox itemLabel="Select All"
        value="#{myBean.selectAllStatus}"
        id="selectAllStatus" style="margin-left:4px;" onchange="selectAllStatus(this);" >
    </p:selectBooleanCheckbox>
    <p:selectManyCheckbox
        value="#{myBean.serviceStatusFilterList}"
        layout="pageDirection" id="empListSub">

        <f:param name="tabValue" value="1" />
        <f:selectItems value="#{serviceCalendarViewBean.serviceStatusList}" var="status"
            itemLabel="#{status.title}" itemValue="#{status.id}"/>
    </p:selectManyCheckbox>
</p:tab>
</p:accordion>

The Javascript called when the 'select all' checkbox is clicked is

function selectAllStatus(element)
{
   var selectAll = element.checked;
   $( 'input[id^="'accord:empListSub'"]' ).each(function(){
        this.checked=selectAll;
   });
}

When i uncheck the 'select all' checkbox, i need the all checkboxs generated by f:selectitems to be unchecked and vice versa.

The below code in the change event's javascript gave me an error in the console. Error is "unexpected syntax error ; "

$( 'input[id^="'accord:empListSub'"]' ).each(function(){
    this.checked=selectAll;
});

In the network the javascript code appears as

$( 'input[id^=&quot;'accord:empListSub'&quot;]' ).each(function(){
     this.checked=selectAll;
});

I tried removing the double quote which was of no use.

So could anybody help me out here.

In jquery, When i uncheck the 'select all' checkbox, i need the all checkboxs generated by f:selectitems to be unchecked and vice versa.

And also when i check or uncheck any of the f:selectItems it also has to call another javascript function.

How do i do that?

4
  • I think the problem is that Primefaces uses theming for checkboxes so you can't just do it the normal jquery way. You have to fiddle with showing/hiding the check-image on the container. I tried it but failed, but I think its possible Commented Aug 23, 2014 at 8:16
  • You forgot to tell the PrimeFaces version. Commented Aug 23, 2014 at 16:14
  • PrimeFaces 4.1 doesn't exist. At least, not as final/official release. Commented Aug 25, 2014 at 11:16
  • sorry :)..my mistake.. Commented Aug 25, 2014 at 13:00

2 Answers 2

1

The problem was with the component referencing

$( 'input[name^=accord\\:empListSub]' ).each(function(i,obj){
    $('div .ui-chkbox-box').addClass('ui-state-active');
    $('span .ui-chkbox-icon').addClass('ui-chkbox-icon ui-icon ui-icon-check ui-c');
 );
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use prop() in jQuery to set the checked property

 $( 'input[id^='+accord:empListSub+']' ).prop("checked",selectAll);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.