In this case you should use generated columns mechanism: documentation.
First of all set an id for a table that contains “Employee_Project” entity:
<table id="emloyeeProjectTable" ...>
...
</table>
Then inject the table in screen controller:
public class Employee_projectBrowse extends AbstractLookup {
@Inject
private Table<Employee_project> emloyeeProjectTable;
// a bean that is used to create UI components that will be used later
@Inject
private ComponentsFactory componentsFactory;
...
}
And add generated column inside of init method:
@Override
public void init(Map<String, Object> params) {
// first parameter should be equal to the corresponding column id
emloyeeProjectTable.addGeneratedColumn("allocationCost", new Table.ColumnGenerator() {
@Override
public Component generateCell(Employee_project employeeProject) {
BigDecimal employeeCtc = employeeProject.getEmployee().getCtc();
BigDecimal allocationCost = employeeProject.getAllocation_percentage().multiply(employeeCtc);
Label allocationCostLabel = componentsFactory.createComponent(Label.class);
allocationCostLabel.setValue(String.valueOf(allocationCost));
return allocationCostLabel;
}
});
}
I would recommend you to use camel case in your code:
instead of Employee_project use EmployeeProject
instead of getAllocation_percentage() use getAllocationPercentage()
instead of employee_projectsDs use employeeProjectsDs
I have tried to follow your steps, but as you can see from the picture above, I still got some error and I wonder why that happen. Did you know why the code still appear in red?
Check that you have all required imports (Component, BigDecimal, Label, etc) and entity getter (getEmployee) has the same name as it used in the column generator.
I apologize, for some reasons I forgot that the same thing can be easily done with CUBA Studio. Use the following actions to re-create IDEA project files: