Web form framework in Java

What are the common ways to build web forms in Java and groovy?

Spring and Grails provide the corresponding taglib, but I wonder if there is a form framework that allows the creation of forms as object sets, dynamic manipulation of elements, embedding sub forms, filling and validation, and rendering

For example, if I have a set of fields that are commonly used in multiple forms, I want to reuse the code In addition, such a group of elements can be part of another group I also want to dynamically reorder elements, change field names and other input field properties, and so on without changing any HTML code

Solution

You can try using the open source Formio library It can be used in many environments / frameworks, and various template frameworks can be used

With Formio, you can manipulate forms using objects: create form definition – mapping, form field definition and nested mapping (for nested objects, such as person's address or address list) Both mapping and form fields can be defined as reusable (immutable) objects and grouped together You can use nested mapping to model reusable "groups" of form fields (and nest them into another group)

Formio supports binding data from Java objects to form definitions, which can then be passed to templates and rendered The data from the request can be validated (using the bean validation API) and bound back to the Java object (to the newly created or provided instance) Supports binding of basic Java types, nested object types, collections or arrays (primitives or complex objects) You can use immutable classes

Form definitions can be pre - populated with data (before passing to the template) and populated with data from the request (validation) Automatic bidirectional data binding is implemented in the "fill" and "bind" methods on the form definition object

Formio is a server - centric library, but it can be used in combination with existing client libraries Rendering is left to the template system For example, using JSP, you can prepare your own reusable tags to render the form definition filled with data and its parts (nested mapping, various types of form fields). These parts already contain all the necessary data to be rendered, including visible, enabled, read-only and other marks You can define your own custom field properties and use them in reusable tag / template fragments, so you don't need to change the HTML code in most cases

Note: I am the author of the library. You can find the source code on GitHub and fork it View the documentation for more details

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>