Computed Pseudofields, also known als calculated fields or computed fields, are fields that rather compute than store they value. Unlike the other field types, like text fields, they contain a "formula" or script that describes the computation of the value instead of a user entered value. 

Use cases

Computed fields are mainly used to:

  • Extract values from another field's value, e.g. the middle inital from a middle name field
  • Combine multiple fields, e.g. the display name as a combination of first name, middle inital and last name
  • Calculations based on a value from one or more other fields, e.g. the grand total based on the VAT and the net price fields. 

Features and Limitations

Let's have a look at their features and limitations:

defined at design-time
Calculated fields are entirely defined by the author of a class, that means standard users without programming rights cannot change anything about them. They don't have a value property and the script is defined by the author of the class. 
calculated at run-time
Everytime a page containing a computed field is requested the value of the computed field is calculated. That means, that the computed field always shows current value, even if it is used to display something highly volatile like the current date and time. But that also means, that you should not overdo it with the number of computed fields and their complexity, else you wiki may decrease in performance
read-only
The standard display for view and edit mode of an calculated field is read-only. So users of your wiki cannot enter any data into the calculated field but only read the value of the calculated field. The value of the computed field will change if the user changes a value of a field that the computed field is based upon.
not queryable
Unlike other fields the value of the computed field is not stored in the database and therefore cannot be part of xwql or hql queries. 

In xwiki the "formula" describing how to compute the value is defined in the script property of the field definition and can be further adjusted using the custom display property.

Tags:
   

Get Connected