Customizing Edit Form Fields

Only persistent 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.

Configuration of the Edit Form consists of three optional parts:

  1. 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.
  2. Defining the list of fields to be displayed: is done in the formView() method of the administration configuration for the endity.
  3. Configuring an editor for a String field. The following editors are available:
    • Text Field
    • Text Area
    • Rich Text Field (aka. WYSIWYG editor)
    • Dropdown Box with a list of predefined options.

In case all the above is omitted, all entity persistent fields will be displayed on the Edit Form, no validation will be performed on saving an entity item, and a String field will have a Text Field editor.

The below example illustrates how to specify the list of fields on the Edit Form, and add validation to some of them.

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;

...

}
...

public class BookingAdministration extends AdministrationConfiguration <Booking>{

	public 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();
	}
}

Edit_Form