Giter Club home page Giter Club logo

java-rink's Introduction

java-rink

Skating in java world! A set of Java utilities:

  • Validation

Validation

This is a Java Validation, Binding and Formatting framework for web based Java application. This little framework will provide a very straight forward way to define your validation rule for each field in your domain object. The purpose is to let the application developer focus on business logic, not coding the validation logic. It is supposed to be very simple and easy to use. Here is a brief introduction of how to use it in your application:

Getting Started

Maven

  <dependency>
    <groupId>com.y-l-w.enterprise</groupId>
    <artifactId>Validation</artifactId>
    <version>${validation.version}</version>
  </dependency>

Components to wire:

Validate Domain Object as Java Bean

  • Create every bean in your project as a subclass of AbstractValidationBean
  • Override the validate() method
  • Specify validation rule and validate each field that need to be validated

Dealing with errors

  • AbstractValidationBean defined a Set of BeanError and a Map of FieldError
  • The framework will populate the Set and Map with validation errors
  • Create an Enum XXXErrorCode implements ErrorMessage interface to categorize error message in your project
  • Create a class XXXError extends BeanError to represent customized error
  • Add a new instance of XXXError to error Set for each error happened in your project

Auto bind Java Bean properties with Form data

  • Create a Binder class for each bean which need to be binded with form data
  • Make the Binder class a subclass of AbstractBeanBinder
  • Override preBind() method to put pre bind logic like populate bean with default values from data source
  • Override buildParameterMap() method to build parameter map, or get it from HTTP request for auto binding
  • Override postBind() method to put customized post bind process logic

Build Form Key Map

The Form Key Map is for making sure:

  • The form key in the front page to be uniqe among context beans
  • The form key used in the front page to be the same as the back end and
  • The form key can be converted to bean property name for auto binding pupose

To achive this - you need to:

  • Add a new constructor to your bean and take beanName string parameter
  • Call setBeanName(beanName) and buildFormKey() methods from constructor to build the form key map
  • Add new constructor to bean builder to build the bean for Web Form
  • Call the new bean constructor which take beanName string parameter
  • Add public static Builder formKeyValues(String beanName) method to return builder with formKey build in the bean
  • Create bean instance for Web Form in your BeanBinder's preBind() method
  • Use key in formKey map as input name in http form (ex: reference from page context in Handlebars template)

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.