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 7618771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:29:28+00:00 2026-05-31T03:29:28+00:00

I am rendering a table with p:dataTable (PrimeFaces) and what I want to do

  • 0

I am rendering a table with p:dataTable (PrimeFaces) and what I want to do is color the background of cells depending on the value of their content. This is different from coloring a row or a column — it is the individual cell.

First a CSS problem. If I do this:

                    <p:column headerText="xyzzy">
                        <div style="background-color: green">
                            <h:outputText value="#{rowVar.anumber}" >
                                <f:convertNumber groupingUsed="true" />
                            </h:outputText>                        
                        </div>
                    </p:column>

the background color just of the content gets set, not the whole cell. In other words the padding is still the default.

Second, I want to make the style string a variable expression. I can add a function to the backing bean, but how do I access the table content in the method? Will this work?

<div style="#{bean.computeCSS(rowVar.number}">

EDIT:

I figured out a way to do the conditional part, but I still need help with the CSS part. My solution looks like:

                    <p:column headerText="xyzzy">
                        <div class="#{rowVar.anumber gt 0 ? 'colored' : ''}">
                            <h:outputText value="#{rowVar.anumber}">
                                <f:convertNumber groupingUsed="true" />
                            </h:outputText>                        
                        </div>
                    </p:column>

Although I dislike getting to fancy in EL, this has the advantage of not needed a backing bean method.

However I still only get the background color set, not the whole cell.

  • 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-05-31T03:29:29+00:00Added an answer on May 31, 2026 at 3:29 am

    You can add a css class to the row and to the column too, that identifies a cell.
    Use the dataTable’s rowStyleClass attribute (example).
    If you want to color multiple rows:

    <p:dataTable value="#{bean.rows}" var="rowVar"
         rowStyleClass="#{rowVar.firstCol gt 0 ? 'firstColColored' : ''}
                               #{rowVar.secondCol gt 0 ? 'secondColColored' : ''}">
         <p:column styleClass="firstCol">...
         <p:column styleClass="secondCol">
    

    css:

    .firstColColored .firstCol {
         background: pink;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am rendering a rails partial and I want to alternate the background color
Using a different background color for odd and even rows is a commonly used
I am rendering a small table (maybe 10-12 cells) which is updated constantly. I
I have a data table like: <h:dataTable id=box-score-away value=#{individualAwayBoxScoreQuery.resultList} var=_bssl> <f:facet name=header> <h:outputText value=Away
I am using jQuery Datatable plugin for rendering a table as jQuery DataTable. I
I am facing a problem rendering a data table when selecting a date from
I'm trying to layout an HTML table (it's tabular data) and it is rendering
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
<h:dataTable value=#{bean.listOfRows} var=eachRow id=theDataTable> <h:column> <p:outputPanel rendered=#{eachRow.visible}> <h:selectManyCheckbox value=#{xxxx} label=#{xxxx}> <f:selectItems value=#{checkBoxItems} var=eachItem itemLabel=#{eachItem.label}
In Visualforce, I'm using an <apex:dataTable> component as follows: <apex:dataTable value={!Qualifications} var=qual styleClass=cv_table >

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.