-
Notifications
You must be signed in to change notification settings - Fork 255
Configuring Edit Form Fields
Irina Kostenko edited this page Jun 3, 2013
·
11 revisions
Only transient fields of an entity can be shown on the Edit Form. The list of supported field types is the same as for [List View, Quick View and Show View](Configuring list view, quick view, and show view display).
Configuration of the Edit Form consists of two parts:
- Specifying validation rules for a field. It is done by marking the field declaration in the entity class definition with one or more JSR-303 annotation. For example,
@NotNull
to mark a field as required,@Size( min = 10, max = 100)
to restrict input value length. - Defining the list of fields to be displayed is done in the
formView()
method of the entity configuration. This step can be omitted, in which case all entity persistent fields will be displayed.
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@Entity
public class Booking implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
@ManyToOne
private User user;
@ManyToOne
private Hotel hotel;
@Basic
@Temporal(TemporalType.DATE)
@NotNull
@Future
private Date checkinDate;
@Basic
@Temporal(TemporalType.DATE)
@NotNull
@Future
private Date checkoutDate;
@NotEmpty
private String creditCard;
@NotEmpty
private String creditCardName;
private int creditCardExpiryMonth;
private int creditCardExpiryYear;
private boolean smoking;
private int beds;
...
}
...
@Administration( Booking.class )
public class BookingAdministration {
public static FieldSetConfigurationUnit formView( final PersistentFieldSetConfigurationUnitBuilder fragmentBuilder ) {
return fragmentBuilder
.field( "checkinDate" ).caption( "Check-In Date" )
.field( "checkoutDate" ).caption( "Check-Out Date" )
.field( "creditCard" ).caption( "Card Number" )
.field( "creditCardName" ).caption( "Card Name" )
.field( "user" ).caption( "Customer" )
.field( "hotel" ).caption( "Hotel" ).build();
}
}