public class CurrentYearFdCalculator implements ICalculator{
publicObjectcalculate()throwsException{//ItdoesthecalculationreturnXPersistence.getManager().createQuery("from PrmYears p where sysdate() BETWEEN p.startDate AND p.endDate").getResultList().get(0);
}
}
packagecom.yourcompany.cgpa.calculators;importjavax.persistence.*;importorg.openxava.calculators.*;importorg.openxava.jpa.*;importlombok.*;@Getter@Setter//TobepubliclyaccessiblepublicclassNextNumberActForYearCalculatorimplementsICalculator{intann;//ThisvaluewillbeinjectedbeforecalculatingpublicObjectcalculate()throwsException{//ItdoesthecalculationQueryquery=XPersistence.getManager()//AJPAquery.createNativeQuery("select max(i.number) from Livres i"+" where i.annee_oid = :iDoid");//Thequeryreturns//themaxinvoicenumberoftheindicatedyearquery.setParameter("iDoid",ann);//WeusetheinjectedyearasaparameterforthequeryIntegerlastNumber=(Integer)query.getSingleResult();returnlastNumber==null?1:lastNumber+1;//Returnsthelastinvoicenumber//oftheyear+1or1ifthereisnolastnumber}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You're right. When you change annee number is recalculated, but not when you click on New. I think number should be recalculated also when the anno calculates its default value, just as you expect. So, add it as a bug with a link to this thread, and we'll fix this issue for future release.
In the meantime, you can solve the issue with your new action that assign the value to anno just to fire the event. For that, add a controller to your controllers.xml like this one:
This bug is already fixed and the fix will be included in 7.6.2, available in November 2025.
BTW, the bug only arose when the calculator returned the entity, so you can fix it without upgrading just in this way:
PrmYearsprm=(PrmYears)XPersistence.getManager().createQuery("from PrmYears p where sysdate() BETWEEN p.startDate AND p.endDate").getResultList().get(0);returnprm.getOid(); // Instead of prm
With 7.6.2 it work with both entity and oid, but with olders version you have to use the oid to avoid the bug.
Help others in this forum as I help you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have a problem my entity contains 2 fields (year and number) with @DefaultValueCalculator but the 2nd field (number) is not calculated.
I have to select a value in the listbox "year" so that the value of the field "number" is calculated
Do you have a solution for this?
Thanks
below the code
package com.yourcompany.cgpa.model;
import javax.persistence.*;
import org.openxava.annotations.*;
import com.yourcompany.cgpa.calculators.*;
import lombok.*;
@Entity @Getter @Setter
public class Livres {
}
package com.yourcompany.cgpa.calculators;
import org.openxava.calculators.;
import org.openxava.jpa.;
import lombok.*;
@Getter @Setter // To be publicly accessible
public class CurrentYearFdCalculator implements ICalculator{
}
Hi Ch,
You're right. When you change annee number is recalculated, but not when you click on New. I think number should be recalculated also when the anno calculates its default value, just as you expect. So, add it as a bug with a link to this thread, and we'll fix this issue for future release.
In the meantime, you can solve the issue with your new action that assign the value to anno just to fire the event. For that, add a controller to your controllers.xml like this one:
<controller name="Livres">
<extends controller="Typical">
<action name="new" icon="library-plus" keystroke="Control N" class="">
</action>
</extends></controller>
The write the next code for your new action:
Help others in this forum as I help you.
Hi Ch,
This bug is already fixed and the fix will be included in 7.6.2, available in November 2025.
BTW, the bug only arose when the calculator returned the entity, so you can fix it without upgrading just in this way:
With 7.6.2 it work with both entity and oid, but with olders version you have to use the oid to avoid the bug.
Help others in this forum as I help you.