User404 User404 - 6 days ago 5
Java Question

How to programmatically change style in an ADF table

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.


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 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";
        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.