GithubHelp home page GithubHelp logo

formaliser's Introduction

Formaliser

Formaliser uses types and standard annotations to read and write HTML forms with Java objects. It is inspired by Ruby on Rails's form builders.

By default, Formaliser produces minimal markup and is HTML5-aware. Many aspects of the markup can be customised.

Installation

Requires Java 6 and Maven (unless you are willing to hunt down dependencies yourself).

  1. git clone this repo
  2. mvn install
  3. Add the following to your POM:
<dependency>
  <groupId>co.mewf.formaliser</groupId>
  <artifactId>formaliser</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Usage

FormWriter formWriter = new FormWriter(MyEntity.class);

formWriter.writeToString("name"); // Returns <div><label>Name</label><input type="text" name="myEntity.name" /></div>
String formHtml = formWriter.writeToString(); // Returns HTML similar to the above for each field in MyEntity

FormReader<MyEntity> formReader = new FormReader<MyEntity>(MyEntity.class);
MyEntity myEntity = formReader.read(params);

Configuration

FormWriter.Config is used to customise various aspects of how forms are written and read.

new FormWriter(MyClass.class, new FormWriter.Config()
  .writer(new FileWriter("myFile.html"))
  .rowWriter(new MyCustomRowWriter()))
  .i18n(new MyFormI18n())
  .inputTypes(new MyInputTypes());
  • writer: The Writer output is directed to. Defaults to null, meaning the output is only available via FormWriter#writeToString. Common values might be a Servlet's or templating engine's output stream.
  • rowWriter: Handles generating the HTML for a single field. Defaults to TemplateRowWriter.
  • i18n: Produces internationlised labels. Defaults to FieldNameFormI18n.
  • inputTypes: Determines the type of input type to use based on Java types. Defaults to Html5InputTypes.

TODO

  • Maven plugin that generates field name info
  • Validation group support
  • JPA support

License

Formaliser in copyright of Moandji Ezana 2013.

Formaliser is licensed under the MIT License.

formaliser's People

Contributors

mwanji avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.