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.
First of all, you have to enable Siena support to your Play! project
Note Just call this command to get last siena version:
play install siena
Then you 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.1
You need to make your Siena entity inherit the class SienaSupport
Note this is exactly the sister class of Play! default class JpaSupport
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
@As(lang={"*"}, value={"yyyy-MM-dd hh:mm:ss"}) // REQUIRED to retrieve the time selected with 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
You need to 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 {
}
You need to 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
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"
Validation with Siena annotations
- @Max/_@Min are managed
- @DateTime is managed and displays a timepicker but you need to add also the following annotation so that it gets the time:
@As(lang={"*"}, value={"yyyy-MM-dd hh:mm:ss"})
Other annotations should be tested and implemented when missing