Skip to main content

Calculated Fields

It is possible to create a ValueField for which the value is not stored in the database, but rather derived based on other values.

First, you will need to define a ValueField with fieldType set to CALCULATED_FIELD:

<field name="totalWeight">
<valueFieldType component="" name="Long"/>

After expanding this, the cruds class will contain a method stub to implement the calculation.

public CrudsResult<Long> performCalculateTotalWeight(ParameterContext<StarshipData> dataParameter) {
StarshipData starshipData = dataParameter.getValue();
Long result = null;

// anchor:custom-calculation-totalWeight:start
result = starshipData.getComponents().stream()
// anchor:custom-calculation-totalWeight:end

return CrudsResult.success(result);

You can then add this Field to a Projection, or as an info Field.