DefaultValueCalculator and Recalculating Values

  • Sean

    Sean - 2013-08-31

    Hi. I am using a calculator I have created in my project to calculate a person's age. This value will only be displayed in the user interface and will not persisted in the database. I used @DefaultValueCalculator to set the age property for display to the user and that works fine. However, I am having trouble getting this value to update if the date of birth (dob) is changed. Below is the code from the class for the entity. The ApplicantAge class is the name of the calculator saved in my project to calculate age. Again, the below works for displaying the age based on a date entered in the 'dob' field. I thought @Depends would cause the 'age' field to be updated whenever 'dob' is changed, but that's not the case.

    private int age;
    public int getAge() {
        return age;

    Thanks in advance,

  • Javier Paniza

    Javier Paniza - 2013-09-02

    Hi Sean,

    @DefaultValueCalculator is for giving the very initial value to a property, usually a persistent one, so when the property already have value it does not work.

    I think you're looking for a calculated property:

    // private int age; // Without attribute
    public int getAge() {
        int age = ... // Calculating
        ... // age
        return age;

    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks