In order to explain how this plugin works we are going to write some code for a dummy example app which contains three type of relations (one-to-many, many-to-one and one-to-one) between four domain classes.
|
Resources Prerequisites FLEX_HOME and GRAIL_HOME must be defined as enviroment variable!! |

user@cubikalabs:~$ grails create-app gsf-test |
user@cubikalabs:~$ cd gfs-test user@cubikalabs:~/gfs-test$ grails install-plugin flex-scaffold user@cubikalabs:~/gfs-test$ grails compile #After installing Grails doesn't compile it. |
user@cubikalabs:~/gfs-test$ grails create-domain-class customer user@cubikalabs:~/gfs-test$ grails create-domain-class company user@cubikalabs:~/gfs-test$ grails create-domain-class phone user@cubikalabs:~/gfs-test$ grails create-domain-class address |
importorg.cubika.labs.scaffolding.annotation.FlexScaffoldProperty
//@FlexScaffoldProperty(labelField="name") is
//The label field is displayed in edit-view
//of the relation external
@FlexScaffoldProperty(labelField="name")
class Company
{
String name
String address
//One-to-Many
static hasMany = [customers:Customer]
static mapping =
{
customers lazy:false, cascade:"none"
}
static constraints =
{
name(blank:false)
address(blank:false)
customers(display:false)//Not view customer in Company's edit-view
}
}
|
class Customer
{
String firstName
String lastName
String email
Date dateOfBirth
Phone phone
List addresses
Company company
String maritalStatus
Integer age
Boolean enabled
static hasMany = [addresses:Address]
static belongsTo = Company
static mapping =
{
addresses lazy:false, cascade:"all-delete-orphan"
company lazy:false, cascade:"none"
}
static constraints =
{
firstName(minSize:2, blank:false)
lastName(maxSize:20)
dateOfBirth()
age(range:18..99)
email(email:true, blank:false)
//if not declared widget, the default component is a ComboBox
maritalStatus(inList:["Single","Married","Divorce","Widower"],widget:"autocomplete")
addresses()
//if inPlace:false, a ComboBox is created in the "edit-view"
//of the class containing it, and it's filled with the information that makes a
// reference of it.
//Besides, it allows to create a new record from the edit-view of the referenced class
//through a button ("add")
//by default inPlace is true
company(inPlace:false, nullable:true)
//The componente will be hidden when the form is setted CREATE_VIEW mode
//and sets the defaultValue, in this case the value is true
//If you wish, use the metaConstraint editView:false to hide component in EDIT_VIEW mode
enabled(createView:false,defaultValue:'true')
}
}
|
class Address
{
String street
Integer number
String zip
String observation
Customer customer
static constraints =
{
street(blank:false)
//if not declared widget, the default
//component is a NumericStepper
number(widget:"textinput")
zip(blank:false)
observation(widget:"textarea")
//Not view customer in Address' edit-view
customer(display:false)
}
}
|
class Phone
{
String number
String type
static belongsTo = Customer
static constraints =
{
//if not declared widget, the default
//component is a NumericStepper
number(widget:"textinput")
type(inList:["Home","Movil"])
}
}
|
user@cubikalabs:~/gfs-test$ grails generate-all-flex company user@cubikalabs:~/gfs-test$ grails generate-all-flex customer |
user@cubikalabs:~/gfs-test$ grails flex-tasks |
user@cubikalabs:~/gfs-text$ grails run-app |
open browser and go to http://localhost:8080/gfs-test
If you want to know how to import a project into FlexBuilder see: How-To import project into eclipse