openxava / documentation / Lombok

Since v6.5 Lombok is included by default in OpenXava Studio and used in the code of Getting Started guide and OpenXava course. So you no longer need to follow the instructions below

To Use Lombok in your project with Eclipse:
  1. Download Lombok.jar from Lombok site -> http://projectlombok.org/
  2. Execute this jar, and point to your eclipse installation.
  3. Copy lombok.jar to yourproject/lib
  4. On your project options, add lib/lombok.jar on Java Build Path/Libraries

Now, your project is ready to use Lombok.
import javax.persistence.*;
 
import org.openxava.annotations.*;
import org.openxava.model.*;
 
import lombok.*;
 
@Entity
public @Data class PruebaPrimera extends Identifiable {
 
    @Column(length=50)
    private String nombre;
 
}

@Data annotation on class generates a lot of information. Getters, Setters, equal() hashCode() toString() ..... and maybe is enough for most of classes. But for more complex classes where you need to take more control over the "code generated", instead @Data over the complete class, you can use @Getter and @Setter annotations over each method. This allows the following code..

package com.testlombok.modelo;
 
import javax.persistence.*;
 
import org.openxava.annotations.*;
import org.openxava.model.*;
 
import lombok.*;
 
@Entity
public class PruebaPrimera extends Identifiable {
 
    @Column(length=50)
    private @Getter @Setter String nombre; // Here, Getter and Setter are autogenerated by Lombok
 
    @Stereotype("HTML_TEXT")
    private @Getter String observaciones; // Here just Getter is autogenerated, to take control over Setter implementation.
 
    public void setObservaciones(String observaciones) {
        // your custom setter .. tu setter personalizado
        this.observaciones = observaciones;
    }
 
}