the module project is hosted by google code at mandubian-play-crud-siena under MIT license
CRUD Siena Play! module How-to
The CRUD (Create, Read, Update, Delete) Siena module generates a fully usable web interface for your Siena Model objects.
Enable Siena support to your Play! project
Note Just call this command to get last siena version:
play install siena
Install CrudSiena module
For Play! <1.1_, install CrudSiena <=1.01:
play install crudsiena-1.01
For Play! >=1.1_, install CrudSiena >=1.1:
play install crudsiena-1.x
Your Siena entity shall inherit SienaSupport
Note this is exactly the sister class of Play! default class JpaSupport (from Play! version 1.0x)
For example:
@Table("employees")
public class Employee extends SienaSupport {
@Id(Generator.AUTO_INCREMENT)
public Long id;
@Column("first_name")
@Max(100) @NotNull
public String firstName;
@Column("last_name")
@Max(200) @NotNull
public String lastName;
@Column("contact_info")
public Json contactInfo;
@Column("hire_date")
public Date hireDate;
@Column("fire_date")
@DateTime // displays a timepicker
public Date fireDate;
@Column("boss")
@Index("boss_index")
public Employee boss;
@Filter("boss")
public Query<Employee> employees;
@Embedded
public Image profileImage;
@Embedded
public List<Image> otherImages;
@Embedded
public Map<String, Image> stillImages;
@EmbeddedMap
public class Image {
public String filename;
public String title;
public int views;
}
public static Query<Employee> all() {
return Model.all(Employee.class);
}
public String toString() {
return firstName + " " + lastName;
}
}
Please be aware of the possibility to manage:
- Json fields
- One to Many relation
- Many to One relation
- Embedded json-serialized objects : single object/list/map
For more information about Siena, go directly to Siena site
Create a controller inheriting class CRUD for each Siena entity requiring CRUD support
Note this is exactly the sister class of Play! default controller CRUD
The name of the Controller class corresponding to a model class can be:
- ModelClassName (this option is valid on in crudsiena because I found it more intuitive)
For example:
public class Employee extends controllers.CRUD {
}
- ModelClassName+'s' (pluralized) (but any char instead of ‘s’ is OK also)
For example:
public class Employees extends controllers.CRUD {
}
- @For(ModelClass) annotation added to your controller
For example:
@For(models.Employee.class)
public class Employees extends controllers.CRUD {
}
Enable routes to the CRUD module
At the beginning of your conf/routes file, add:
* /admin module:crudsiena
You can get more information at original CRUD module site
Play Validation with Siena annotations
These are Siena model Annotations managed by the CrudSiena module:
- @Siena.Max(NB_CHAR) is managed (enhancer creates dynamically a @play.data.validation.MaxSize(NB_CHAR) )
- @Siena.NotNull is managed (enhancer creates dynamically a @play.data.validation.Required )
- @DateTime is managed and displays a timepicker
Play Validation with Play annotations
These are Play Annotations managed by the CrudSiena module:
- @Required is managed and displays an error if the field is not filled
- @Password is managed and displays a password text field
You can’t use Play! binding annotations
Specific CrudSiena annotations
- @CrudUnique is a new Annotation not provided by Play neither Siena. It verifies a field value is unique in its table.
(thanks to Spreiter301 for his contribution... see googlecode issue)
Be careful this annotation calls DB requests that can be quite heavy so it might impact your application performance. (I will try to provide a mechanism to control where this annotation is applied but it is not so trivial)
Known Limitations
GAE
- @Id annotated field corresponding to the primary key must be Long type
- @Id annotated field corresponding to the primary key must be called "id"