Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:25:29+00:00 2026-06-15T22:25:29+00:00

I have a <p:dataTable> , with a checkbox on the last column. I want

  • 0

I have a <p:dataTable> , with a checkbox on the last column. I want to color the rows of the table based on the status of the checkbox.

<p:dataTable var="acs" value="#{myBean.listaRevogaveis}"
emptyMessage="#{rotulo.mensagemSemDados}" paginator="true"
rows="10" id="tableacs"
paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
<p:column headerText="Nome" sortBy="#{acs.nome}"
filterBy="#{acs.nome}">
<h:outputText value="#{acs.nome}" />
</p:column>
<p:column headerText="Address" sortBy="#{acs.address}" filterMatchMode="contains"
filterBy="#{acs.address}" filterMaxLength="8">
<h:outputText value="#{acs.address}" />
</p:column>
<p:column headerText="Perfil" sortBy="#{acs.cdPerfil}"
filterBy="#{acs.cdPerfil}"  filterMaxLength="2">
<h:outputText value="#{acs.cdPerfil}" />
</p:column>
<p:column headerText="Cadastramento">
<h:outputText value="#{acs.tsSolicitacao}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Concedido">
<h:outputText value="#{acs.concedidoPor}" />
</p:column>
<p:column headerText="Revogar">
    <p:selectBooleanCheckbox value="#{acs.ativo}" >
<p:ajax event="valueChange" oncomplete="toggleColor(this, #{acs.ativo}" listener="#{myBean.checkBox}" update="@form"/>
</p:selectBooleanCheckbox>
</p:column>
</p:dataTable>

So on the toggling of #{acs.ativo} I want that row to receive a different background color.

Following the answer of this question I tried to add this to my xhtml:

<style type="text/css">
.linhaDestacada {   background-color: red !important;}
</style>
<script type="text/javascript">
    function toggleColor(col, status) {

        var linha = jQuery(col).parent();

        if(status) {
            linha.removeClass('linhaDestacada');
        } else {
            linha.addClass('linhaDestacada');           
            }
        }

</script>

But that’s of no use. I put some alerts to see if the function was being called, it is. However, trying to see the tagName, or any property of the linha variable returns null.

There is another interesting point, the callback is being called with the previous value of the checkbox. When box is checked, javascript toggleColor() is receiving false on the status, when its unchecked it receives true.

How can I make the row background toggle together with the checkbox toggle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:25:30+00:00Added an answer on June 15, 2026 at 10:25 pm

    Ok, there were a TON of bugs and problems in that one.

    First:

    primefaces sets the background of the rows to a blank image (depending on the skin). you have to override the url() of the background, so the CSS should look like:

    .linhaDestacada { background: url(”) red !important;}

    Second:

    Calling the javascript from the ajax tag was causing the jQuery to find nulls (dunno why). move the callback to the checkbox tag, using its onchange attribute.

    The final javascript fragment was:

        <script type="text/javascript">
        function toggleColor(col, status) {
    
            var linha = jQuery(col).parent().parent().parent().parent().parent();
    
            if(status) {
                linha.removeClass('linhaDestacada');
                //alert("remove " + linha.html());
            } else {
                    linha.addClass('linhaDestacada');
                    //alert("add "  + linha.html());
    
                }
            }
    
         </script>
    

    Third:

    Updating the WHOLE form is a no-no (the css class you added with javascript was being erased)… you should update only what really matters (in this case, the checkbox and the command button.

    <p:selectBooleanCheckbox value="#{acs.ativo}" onchange="toggleColor(this, #{acs.ativo})">
        <p:ajax event="valueChange" listener="#{myBean.checkBox}" update="@this :formAcesso:btnRevogaNuke" />
    </p:selectBooleanCheckbox>
    

    Fourth:

    the commandButton was not rendering. It would be updated on the ajax response, but the browser did not display it. Found this answer, and moved the id btnRevogaNuke on the encapsulating element:

    <h:panelGroup id="btnRevogaNuke" layout="block">
        <p:commandButton icon="ui-icon-alert" value="Confirmar rendered="#{myBean.confirmar()}" style="margin-left:600px;" action="#{acessoBean.revogaTodos()}" process="@this @form" update="@form" />
    </h:panelGroup>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSF h:datatable with rows of data: <h:dataTable id=dataTable value=#{SessionsController.dataList} binding=#{table} var=item>
I have a primeface datatable as follows <p:dataTable id=associatedProductsTable var=oap value=#{checkoutController.associatedProducts} styleClass=cssAssociatedProductsTable> <p:column>#{oap.product.code}</p:column> <p:column>
I have this JSF table: <h:dataTable id=itemsTable value=#{SelectionBean.selectedItems} var=item > <f:facet name=header> <h:outputText value=Items
I have datatable with column name tag and 100 rows of data.I need to
I have a datatable where I want to change the color of a cell
I have datatable with multiple checkbox selection (PF 3.3.1). I've defined column: <p:column selectionMode=multiple/>
I have a DataTable with one of the column is checkbox. I can select
I have a <ice:dataTable> and I want to add a checkbox to each row.
I have a WPF User control that binds to a DataTable and generates CheckBox
Does anyone have examples on how to create a Datatablest filter checkbox? I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.