...
To prevent a property from being generated you can add the @IgnoreGeneration annotation to its getter method. Do not add it to the field: modelwise properties have no fields, so adding things there is an abomination and causes yet another heap of horrible problems.
Using typeful properties in code
You should generate typed properties for all classes that have properties that are used in your code with either QCriteria queries or DomUI data binding. This means that at least the following classes should be generated:
- All Entity classes used by JPA/Hibernate
- All model classes used in (DomUI) views
Warning |
---|
The properties generator is a recent addition, and updating DomUI's code base to use them is a work in progress. |
Typed properties can be used on every location where you would normally use a string containing a property path. For instance the following code:
Code Block |
---|
private RowRenderer<Line> createRowRenderer() {
RowRenderer<Line> rr = new RowRenderer<>(Line.class);
rr.column().label("Period from").renderer(createMonthRenderer("from"));
rr.column().label("Period till").renderer(createMonthRenderer("till"));
rr.column("amountType").editable().factory(createAmountTypeControlFactory());
rr.column("percentage").editable().factory(createPercentageControlFactory());
rr.column("amount").editable().factory(createAmountControlFactory());
rr.column().label("Divide").renderer(createDivideRenderer());
if(!model().isReadOnly()) {
rr.column().renderer(createRemoveRenderer()).width("1%").nowrap();
}
return rr;
} |
uses strings as property names. It is easily replaced by the equivalent code with typed properties:
Code Block |
---|
private RowRenderer<Line> createRowRenderer() {
RowRenderer<Line> rr = new RowRenderer<>(Line.class);
rr.column().label("Period from").renderer(createMonthRenderer(Line_.from()));
rr.column().label("Period till").renderer(createMonthRenderer(Line_.till()));
rr.column(Line_.amountType()).editable().factory(createAmountTypeControlFactory());
rr.column(Line_.percentage()).editable().factory(createPercentageControlFactory());
rr.column(Line_.amount()).editable().factory(createAmountControlFactory());
rr.column().label("Divide").renderer(createDivideRenderer());
if(!model().isReadOnly()) {
rr.column().renderer(createRemoveRenderer()).width("1%").nowrap();
}
return rr;
} |
The advantages are plenty: since the properties are typed all parts of the RowRenderer are now typeful. So for instance adding a renderer now shows the proper type instead of ?:
This is invaluable in for instance bindings with conversion, where it is important to be able to know what is converted to what else:
TBD
It is also very useful for refactoring: the moment either the type or the name of a property changes the compiler will immediately signal problems. It is also easy to do impact analysis: just search for occurrences of a property method to see what code would be impacted by a change.