Search code examples
cuba-platform

Entity attribute initial value (YEAR)


we have problem in Entity Designer whith default fields values.

How can i set in a field PERIODO actual YEAR of created ?

package com.company.imgestion.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Column;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.sun.org.apache.xerces.internal.impl.dv.xs.YearDV;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@Table(name = "IMGESTION_PRESUPUESTOS")
@Entity(name = "imgestion$Presupuestos")
public class Presupuestos extends StandardEntity {
private static final long serialVersionUID = -1609660502101484095L;

@Column(name = "PERIODO")
protected Integer periodo;

public Integer getPeriodo() {
    return periodo;
}

public void setPeriodo(Integer periodo) {
    this.periodo = periodo;
}
}

Solution

  • See these examples: https://doc.cuba-platform.com/manual-6.2/init_values.html

    The simplest solution would be assigning an initial value to the entity field:

    @Column(name = "PERIODO")
    protected Integer periodo = Calendar.getInstance().get(Calendar.YEAR);