This discussion is archived
5 Replies Latest reply: Oct 30, 2009 3:51 AM by Arunkumar Ramamoorthy RSS

color of rows in <af:table>

708783 Newbie
Currently Being Moderated
Hi,

I am using <af:table> to create a table on page. I already have few rows in this table. Now i would add new rows in to the table but i want color of new rows to be different to identity newly added rows with existing ones.
Please help how can i change the color of row while adding rows to this table. (rows will be added when user selects some details and click on add command button).

Thanks .!
  • 1. Re: color of rows in <af:table>
    Arunkumar Ramamoorthy Guru
    Currently Being Moderated
    Hi,

    Try this.

    Add this code in your RowImpl class.
        public String getRowStatus(){
            String rowStatus = null;
            System.out.println("\n************ getRowStatus method is called");
            try {
                switch (this.getEntity(0).getEntityState()) {
                case Entity.STATUS_INITIALIZED:
                    {
                        rowStatus = "Initialized";
                        break;
                    }
                case Entity.STATUS_MODIFIED:
                    {
                        rowStatus = "Modified";
                        break;
                    }
                case Entity.STATUS_UNMODIFIED:
                    {
                        rowStatus = "Unmodified";
                        break;
                    }
                case Entity.STATUS_NEW:
                    {
                        rowStatus = "New";
                        break;
                    }
                }
            } catch (Exception e) {
                // TODO: Add catch code
                e.printStackTrace();
            }
            System.out.println("\n****** Row Status: "+rowStatus);
            return rowStatus;
        }
    }
    And, call this method for setting inlinestyle of the item. Say,
              <af:outputText  value="#{row.row.rowStatus}"
                             inlineStyle="#{row.row.rowStatus=='New'?'background-color:Gray;':''}"/>
    This will set the background color of the output text to Gray for the New rows and white for the existing rows.

    -Arun
  • 2. Re: color of rows in <af:table>
    708783 Newbie
    Currently Being Moderated
    Thanks for your reply.

    I am using jar provided for this tag to use. I dont have rowImpl class in my project.
    Please help.
  • 3. Re: color of rows in <af:table>
    Arunkumar Ramamoorthy Guru
    Currently Being Moderated
    Hi,

    Do you have the view object in your project?(which you are using as table?). If yes, you can generate the RowImpl for the view object.(In the view object editor, select java tab and generate rowimpl class).

    -Arun
  • 4. Re: color of rows in <af:table>
    727171 Newbie
    Currently Being Moderated
    Hello,

    What is the best way for setting a row's color conditionally? I added a transient attribute "IsActive" to the view i am using. Setting following expression for each columns's innerstyle property is working good but i wonder if there is a more efficient way to do this.

    #{row.bindings.IsActive=='false'?'color:Gray;':''}
  • 5. Re: color of rows in <af:table>
    Arunkumar Ramamoorthy Guru
    Currently Being Moderated
    Hi,

    Its depending on the requirement. If you have only one application / one table where you'd want to display a row in different color, you can use the method i've given above.

    However, if you want to implement the same behavior across your entire application (for all the tables), you can create a style and apply that style based on the condition (instead of every column) for the table.

    Also, you can try out this java script approach.

    http://technology.amis.nl/blog/2539/adding-table-row-highlighting-to-adf-faces-pages (I've not tried that yet though).

    -Arun

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points