Table with StyleProvider

Hi
I’m using Cuba Platform Studio 6.10.2 and platform-6.10.7

I need to conditionally format same cells in a grid.
I followed Cuba documentation and tis is my code:

public class Tab1Browse extends AbstractLookup {

@Inject
private Table<Tab1> tab1;

@Override
public void init(Map<String, Object> params) {
    tab1.setStyleProvider(new Table.StyleProvider<Tab1>() {
        @Nullable
        @Override
        public String getStyleName(Tab1 entity, @Nullable String property) {
           // omitted code 
           return null;
        }
    });
}
}

I costantly receveive an NullPointerException error when the screen is open.
I don’t know how to resolve this issue.
Can someone help me?
Thank you

Test01.zip (81.0 KB)

Hi!

It seems you try to inject wrong table id. In the layout you use tab1sTable:

<table id="tab1sTable"
       ...>

so in the controller you should use following code:

@Inject
private Table<Tab1> tab1sTable;

@Override
public void init(Map<String, Object> params) {
    tab1sTable.setStyleProvider(new Table.StyleProvider<Tab1>() {
        @Nullable
        @Override
        public String getStyleName(Tab1 entity, @Nullable String property) {
            return null;
        }
    });
}
1 Like