I have a simple boolean column. My current task is to disply instead of the standard checkbox that CUBA Platform provides a red or a green circle (or anything similar)
In order to do so I created a Formatter as follows (simplified)
package com.company.myproject;
import java.util.function.Function;
public class BooleanFormatter implements Function<Boolean, String> {
@Override
public String apply(Boolean booleanValue) {
return booleanValue ? "<strong>yes</strong>" : "<small>no</small>";
}
@Override
public Function compose(Function before) {
return null;
}
@Override
public Function andThen(Function after) {
return null;
}
}
And then I assign the Formatter to my column in the screen as follow
Hi,
Instead of the formatter, you should use custom column generator.
Generate Label as cell component and set htmlEnabled="true" for it.
See more example of HTML content in Label here: Label - CUBA Platform. Developer’s Manual
You can also use programmatic method: Table#addGeneratedColumn()
Then the code will be more compact.
/**
* Add a generated column to the table.
*
* @param columnId column identifier as defined in XML descriptor. May or may not correspond to an entity property.
* @param generator column generator instance
*/
void addGeneratedColumn(String columnId, ColumnGenerator<? super E> generator);
Thanks @albudarov, I will keep that in mind… I can’t test / implement this in the near future, as I’m working on other issues atm… But I will get back to that.