2

I got an ADF table generated form my data controls. But I need to change the style of every cell in my backing bean. I can't really find anything useful on google, hopefully you can provide me with some useful information.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
User404
  • 2,152
  • 2
  • 27
  • 35

3 Answers3

2

Can you be a bit more specific? Which jdev version? If you need to change each cell why not using a skin?

Based on the comments we now know that you use jdev 11.1.2.2.0. What you can do is to bind the styleClass property of the table to a backing bean property. The property in the bean has a getter and a setter method. In the setter method you can get all the values you need from the row and do you calculation. Based on the outcome you return the name of a style class suitable for the cell. The different style classes you define in a skin fro the application. If you e.g. defien the following style classes in your skin

.high_value { background-color:green; }
.negative_value { background-color:red;}

and in a bean in request scope, which you access from the page the table is on

    private String styleForCell;

public String getStyleForCell()
{
    // get the value of the cell
    FacesContext lContext = FacesContext.getCurrentInstance();
    ELContext lELContext = lContext.getELContext();
    ExpressionFactory lExpressionFactory = lContext.getApplication().getExpressionFactory();
    Number val;
    val = (Number) lExpressionFactory.createValueExpression(lELContext, "#{row.valargument}", Object.class).getValue(lELContext);
    if (val == null)
        return "";

    // do the calculation and return the suitable style class
    int ival = val.intValue();
    if (ival >= 100000 )
        return "high_value";
    else if (ival < 0)
        return "negative_value";
    else 
        return "";         
}

public void setStyleForCell(String aStyleForCell)
{
    this.styleForCell = aStyleForCell;
}

Now you can access the calculated style class from the tables column styleClass property as #{beanname.styleForCell} This will call the method for each cell of the column.

Timo Hahn
  • 2,466
  • 2
  • 19
  • 16
2

Use a conditional EL in your field's inlineStyle to set the style based on the value. Something like #{binding.value > 1000 ? 'font=bold' : 'font=regular'}

Shay Shmeltzer
  • 3,693
  • 1
  • 13
  • 9
  • The problem is that I don't know the particullar value (in your example 1000). That's why I need to do it in my bean because I need to get the ID from the selected row, get the corresponding data from my webservice and then check the value of each cell and if needed, change the style. – User404 Jul 19 '12 at 07:34
0

+1 on the previous answer. Note that the way you change the cell coloring pretty much depends on the use case. If your use case requires dynamic ad-hoc color coding then the answer is different as if the requirement is to change color coding to implement a corporate branding

Frank

  • I need to compare the data in my table to data from webservice. When the data is different, the value of that cell needs to be in bold and a red (or other) color. – User404 Jul 17 '12 at 10:50