User404
User404

Reputation: 2192

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.

Upvotes: 2

Views: 7028

Answers (3)

Timo Hahn
Timo Hahn

Reputation: 2496

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.

Upvotes: 2

Shay Shmeltzer
Shay Shmeltzer

Reputation: 3721

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'}

Upvotes: 2

Frank Nimphius-Oracle
Frank Nimphius-Oracle

Reputation: 711

+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

Upvotes: 0

Related Questions