Operation
Next to manipulating data, there are also scenario’s in which case we want to write a custom method, for these cases we introduced to @Operation annotation to be used in your Customization Java Class. You can write any java code including input and return parameters and use the @Operation method to generate an operation on the Data Control.
@Operation public BigDecimal calculateYearlySalary(XMLDCElement employee, BigDecimal salesVolume) { BigDecimal retval = null; BigDecimal salary = (BigDecimal) employee.get("salary"); BigDecimal commissionPercentage = (BigDecimal) employee.get("commissionPercentage"); if (salesVolume == null || salary == null || commissionPercentage == null) { return retval; } retval = salary.add(salesVolume.multiply(commissionPercentage)); return retval; }
The return type of the method is used to create the return attribute in the Data Control.Â
The first argument has to be an XMLDCElement, but after that you can use as many other arguments as you please.
In this case, we ask for a salesVolume input to calculate the yearly salary. The result will look as followed in the Data Control panel:
We can now drag and drop the BigDecimal return type of the method into our Employee form.Â
These will result in a popup to edit the Action Binding. Here you typically point to where the data comes from that you want to use as input. For the purpose of this example we will just enter a fixed value of 50.000.
Â
Now you also need to drag and drop the button on the screen since you need to fire the method:
Add a partialtrigger on the result field, pointing to the Form Layout:
Â
After this run the page, it should look like this:
Â
Press the button and the result should be shown in the page: