Skip to content

Form Extension #483

@hurelhuyag

Description

@hurelhuyag

I used to dream about auto-generating jakarta validation annotations into HTML input attributes. This way, both front-end and back-end could have same validation. Since JTE has extensions, I'm wondering if this is possible.

For example lets declare model like this:

import jakarta.validation.constraints.NotEmpty;
record DemoForm(@NotEmpty String firstname, @NotEmpty String lastname) {}

And write jte template something like this:

@param DemoForm form
@form(form)
  @form.input("firstname")
  @form.input("lastname")
  <button>Submit</button>
@endform

Then compile time generates output:

<form>
  <input name="firstname" value="${form.firstname()}" required="true" />
  <input name="lastname" value="${form.lastname()}" required="true" />
  <button>Submit</button>
</form>

required="true" is generated because of @NotEmpty annotation.

Is this possible with JTE extensions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions