crud module: add a @InputType annotation to define the html input type of the field

Bug #562707 reported by xiaocase
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
New
Undecided
Arthur Embleton

Bug Description

step 1. define @InputType:::::

import jxp.enums.Component;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface InputType {
    /** html input type */
    Component component() default Component.text;

    /** html input field size */
    int size() default 20;

}

step 2. define Enum Component::::

public enum Component {

    text, password, textarea, richeditor, checkbox, number, date, datetime, file, select, spinner, slider, rating, colorpicker
}

step 3. use @InputType in entities:::

@Entity
public class User extends Model {

  @InputType(Component=Component.text, size=30)
  public String name;

  @InputType(Component=Component.password)
  public String password;

  @InputType(Component=Component.richeditor)
  public String profile;

  @InputType(Component=Component.date)
  public Date birthday;
}

step 4. use with CRUD and controllers:::

just add these lines to CRUD -> ObjectField::

   ....
   /** use to check if the field is unique */
   public boolean unique;

   public ObjectField(Field field) {
      ......
      if (field.isAnnotationPresent(InputType.class)) {
           type = field.getAnnotation(InputType.class).component().name();
      }
      if (field.isAnnotationPresent(Column.class)) {
           unique = field.getAnnotation(Column.class).unique();
      }
      name = field.getName();
   }
  .....

  Then, we can define all the input types. and it will not limit to JPA and Play's annotations. and we can add a 'exists' to crud to check if the field is unique (by ajax or validation before save).

Related branches

Revision history for this message
Arthur Embleton (aembleton) wrote :

I will implement this as part of the richCrud branch that I am working on: https://code.launchpad.net/~aembleton/play/richCrud

Changed in play:
assignee: nobody → Arthur Embleton (aembleton)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.