Form Module
Annotation-driven form generation from Java beans.

In 30 seconds

Annotate Java beans with @Form, @FormItem, @FormSection, and @Bounds, then call DefaultFormBuilder.createForm() to obtain a styled JavaFX Node. No hand-built form layout required.

Quick Start

Add the form module, annotate a Java bean, and build a JavaFX node with DefaultFormBuilder.

<dependency>
    <groupId>org.jrebirth.af</groupId>
    <artifactId>form</artifactId>
    <version>${jrebirth.version}</version>
</dependency>

Minimal example — single-section form:

@Form
public class PersonBean {

    @FormItem
    @Bounds
    private String firstName;

    @FormItem
    @Bounds
    private String lastName;

    @FormItem
    private int age;
}

// In your View initView():
FormBuilder builder = new DefaultFormBuilder();
Node formNode = builder.createForm();
myContainer.getChildren().add(formNode);

For multi-section forms, nest beans annotated with @FormSection (see ComposedFormBean in the form module tests).

Form

Overview

The JRebirth Form module provides annotation-driven form generation from Java beans. By annotating your bean classes and fields with a set of dedicated annotations, you can generate complete JavaFX form UIs without writing layout code manually.

The module follows a declarative approach:

  1. Annotate a Java bean with @Form.
  2. Mark fields with @FormItem to include them in the generated form.
  3. Group items into sections with @FormSection.
  4. Add validation constraints with @Bounds.
  5. Call a FormBuilder to produce the JavaFX Node tree.

Annotations

@Form

The @Form annotation is placed at the class level to mark a bean as a form source. Any class annotated with @Form can be processed by the FormBuilder.

@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Form {
}

Place @Form on the root bean class. Nested section beans also carry @Form when they are standalone form sources.

@FormItem

The @FormItem annotation marks fields or methods that appear as form fields in the generated layout.

@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface FormItem {
}

Example from the form module test sources:

@Form
public class SingleFormBean {

    @FormItem
    private int size;

    @FormItem
    private double angle;

    @FormItem
    private String name;
}

(from form module tests: org.jrebirth.form.test.bean.SingleFormBean)

@FormSection

The @FormSection annotation groups form items into logical sections. Each section is rendered as a distinct visual block in the generated form, helping organize complex forms into manageable parts.

@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface FormSection {
}

Compose sections by nesting form beans:

@Form
public class ComposedFormBean {

    @FormSection
    private SingleFormBean singleFormBean;

    @FormSection
    private SingleBisFormBean singleBisFormBean;
}

@Bounds

The @Bounds annotation provides validation constraints for form fields. Apply it to fields or methods alongside @FormItem to enforce constraints such as minimum/maximum values, required status, or patterns.

@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Bounds {
}

Pair @Bounds with @FormItem on fields that require validation in the generated UI.

FormBuilder Interface

The FormBuilder interface defines the contract for building JavaFX form nodes. It exposes a single method:

  • createForm() — produces a Node representing the complete form UI.
public interface FormBuilder {

	/**
	 * Create a form node
	 * 
	 * @return
	 */
	Node createForm();
}

DefaultFormBuilder

DefaultFormBuilder is the default implementation of FormBuilder. It generates a structured form layout using VBox containers for sections and HBox rows for individual fields, with separators between entries.

public class DefaultFormBuilder implements FormBuilder {

	

	@Override
	public Node createForm() {

    	VBox rootBox = VBoxBuilder.create()
    			.spacing(10)
    			.build();
    	
    	
    	rootBox.getChildren().addAll(
    			buildVBox(),
    			buildVBox(),
    			buildVBox()
    			);
    	
        AnchorPane.setTopAnchor(rootBox, 10.0);
        AnchorPane.setLeftAnchor(rootBox, 10.0);

        return rootBox;

    }

	private VBox buildVBox() {
		final VBox contentBox = VBoxBuilder.create()
                .styleClass("Form")
                .prefWidth(200)
                
                .build();



        contentBox.getChildren().add(createField("FIELD", "km/h"));
        contentBox.getChildren().add(createLine());
        contentBox.getChildren().add(createField("Field", "km/h"));
        contentBox.getChildren().add(createLine());
        contentBox.getChildren().add(createField("Field", "km/h"));
        contentBox.getChildren().add(createLine());
        contentBox.getChildren().add(createField("Field", "km/h"));
        contentBox.getChildren().add(createLine());
        contentBox.getChildren().add(createField("Field", "km/h"));
		return contentBox;
	}

    private Node createLine() {

        return LineBuilder.create()
        		.styleClass("FormSeparator")
                .startX(0).startY(0)
                .endX(200).endY(0)
                .stroke(Color.GREY)
                .strokeWidth(1)
                .effect(DropShadowBuilder.create()
                        .offsetX(0)
                        .offsetY(1)
                        .radius(1)
                        .color(Color.web("262626"))
                        .build())
                .build();
    }

    private Node createField(final String string, final String string2) {

        final HBox box = HBoxBuilder.create()
        		.styleClass("FormRow")
        		.alignment(Pos.CENTER_LEFT)
        		.build();

        final Label fieldLabel = LabelBuilder.create()
                .text(string)
                .styleClass("FieldLabel")
                .alignment(Pos.BASELINE_LEFT)
                .build();

        final Label unity = LabelBuilder.create()
                .text(string2)
                .styleClass("FieldUnity")
                .build();

        final Label fieldValue = LabelBuilder.create()
                .text("...")
                .styleClass("FieldValue")
                .build();

        box.getChildren().addAll(fieldLabel, unity, fieldValue);
        return box;
    }
}

Each field row is an HBox with label, unit, and value columns, separated by styled Line separators. CSS classes (Form, FormRow, FieldLabel, etc.) control appearance.

Annotating a Bean

@Form
public class PersonBean {

    @FormSection
    private String personalInfo;

    @FormItem
    @Bounds
    private String firstName;

    @FormItem
    @Bounds
    private String lastName;

    @FormItem
    private int age;
}

Building the Form

FormBuilder builder = new DefaultFormBuilder();
Node formNode = builder.createForm();
myContainer.getChildren().add(formNode);

The generated form respects the section grouping and field ordering defined by the annotations, producing a consistent and styled UI with minimal boilerplate.