Skip to content

marccollin/formatic

Repository files navigation

Formatic

Overview

Formatic is a Java framework for automatic web form generation based on annotations. It enables the creation of dynamic HTML forms by simply annotating Java class fields, eliminating the need to manually write HTML code. Actually thymeleaf template engine is used. Other can be added.

Modular Architecture

🎯 formatic-core - Core Module

Role: Framework core, independent of any web framework Responsibilities:

Form annotation definitions (@TextInput, @FormInput)
Field metadata management (FormFieldMetadata)
Annotation processing handlers (FormFieldAnnotationHandler)
Metadata builder (FormFieldMetadataBuilder)
Caching system for performance optimization

🔧 formatic-spring - Spring Integration Module

Role: Integration with Spring Boot ecosystem Responsibilities:

Spring Boot auto-configuration (FormaticSpringAutoConfiguration)
Automatic bean registration (handlers, builders)
Thymeleaf templates for form rendering with boostrap, tailwind css Automatic component scanning

🎨 formatic-example - Demo Module

Role: Usage examples and capability demonstration Responsibilities:

Spring MVC controller (FormaticController)
Example DTOs (Editor)
Test endpoints (/formnew, /formhybrid, /formfeeded)
Can be used with mvc or rest application

Design Principles

🎯 Separation of Concerns

Core logic independent of web frameworks
Spring integration as separate module
Clear boundaries between layers

🔧 Extensibility

Plugin-based handler system
Easy to add new field types
Customizable rendering templates

⚡ Performance

Metadata caching with ConcurrentHashMap
Single-pass field processing
Lazy initialization of handlers

🔒 Type Safety

Generic handler interfaces
Compile-time annotation validation
Reflection-based but type-safe processing

Use Cases

Rapid Prototyping: Quick form creation for demos
Admin Panels: Auto-generated CRUD forms
Dynamic Forms: Forms that change based on configuration
Multi-tenant Applications: Different form layouts per tenant
API Documentation: Auto-generated form examples

This library follows the principle of "convention over configuration," making form creation as simple as adding annotations to your domain objects.

Requirements 🔧

  • Java 21 or higher.

Using Formatic

Select a formatic annotation

  • CheckboxInput
  • DateInput
  • EmailInput
  • FileInput
  • HiddenInput
  • NumberInput
  • PasswordInput
  • PhoneInput
  • RadioInput
  • SelectInput
  • TextareaInput
  • TextInput
  • UrlInput

and attach it to a field in your class

public class Editor {

    @HiddenInput
    private Long idEditeur;

    @TextInput(minLength = 2, maxLength = 20, label = "name")
    private String name;

    @TextInput
    private String address;

    @TextInput
    private String address2;

    @SelectInput(optionsProvider = "getCities", required = true)
    private String city;

    @SelectInput(optionsProvider = "getProvinces", required = true)
    private String provinceState;

    @TextInput
    private String country;

    @TextInput(pattern = "[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]", maxLength = 7, placeholder = "A1A 1A1", title = "Enter a valid Canadian postal code (e.g., A1A 1A1)")
    private String codePostal;

    @PhoneInput(pattern = "[0-9]{3}-[0-9]{3}-[0-9]{4}", placeholder = "514-272-2323")
    private String phone;

    @CheckboxInput
    private boolean confidential;

    @EmailInput
    private String email;

    @UrlInput
    private String webSite;

    @DateInput
    private LocalDate birthDate;

    @TextareaInput(rows = 5, cols = 50, required = true)
    private String comment;

    @CheckboxInput(options = {"sportCheck:Sport", "musiqueCheck:Musique", "lectureCheck:Lecture"})
    private List<String> interest;

    @RadioInput(options = {"visa:Visa", "paypal:Paypal"})
    private String paymentMethod;
}

Thymeleaf template use actually boostrap and tailwind css library. Bootstrap have vertical and horizontal form. Tailwind have vertical form.

Result of processing Editeur class with boostrap horizontal form

Formatic editor example process

Result of processing Editeur class with tailwind vertical form Formatic editor example process

DataSource for RadioInput, CheckBoxInput and SelectInput

Static or dynamic source can be provided, in the example both way are shown.
Dynamic source search in the classpath the method name provided.

Dynamic

Method name to call must be specified in the optionsProvider attribute

    @SelectInput(optionsProvider = "getCities", required = true)
    private String city;

Static

Values must be specified in the options attribute

    @CheckboxInput(options = {"sportCheck:Sport", "musiqueCheck:Musique", "lectureCheck:Lecture"})
    private List<String> interest;

Thank You!

Please ⭐️ this repo and share it with others

Contributing 💡

If you want to contribute to this project and make it better with new ideas, your pull request is very welcomed. If you find any issue just put it in the repository issue section, thank you.

About

Formatic is a Java framework for automatic web form generation based on annotations.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors