Well, if you look at the ObjectType class, it scans only public Fields:
for (Field f : entityClass.getFields()) {
...
}
I could change that by using getDeclaringFields(), but it would ignore
inherited fields ... Or use both and do a marge ... I'm not sure what
is the best solution but I will not change that for now because we are
in the 1.0 release process and it would change the way that existing
applications work.
----
In fact you can let your fields public even if you define your own
getter/setter.
Play will always use the defined getter or setter if exists. Look at this code:
@Entity
public class Data extends Model {
@Required
public String value;
public Integer anotherValue;
public Integer getAnotherValue() {
if(anotherValue == null) {
return 0;
}
return anotherValue;
}
public void setAnotherValue(Integer value) {
if(value == null) {
this.anotherValue = null;
} else {
this.anotherValue = value * 2;
}
}
public String toString() {
return value + " - " + anotherValue;
}
}
From another class, you can try:
Data data = new Data();
data.anotherValue = null;
assert data.anotherValue == 0;
data.anotherValue = 4
assert data.anotherValue == 8;
And you can try with my crud3 sample, all the generated forms will
work using getter/setter for the anotherValue field.
It is more the way that Scala works than the classic Java standard ...
----
To hide some fields from the generated forms, you can either make them
private, or define your own fields lists in the #{crud.form /} :
#{crud.form fields:['value'] /}
Or to make some fields read only:
#{crud.form}
#{crud.custom 'anotherValue'}
${object.anotherValue}
#{/crud.custom}
#{/crud.form}
Guillaume ++