14. Step 4. Don't add a manager layer to
MVC (yet). KISS + YAGNI.
edit(mapping, form, request, response) {
if (form.getId() != null) {
person = Person.find(form.getId());
form = convert(person);
updateFormBean(mapping, request, form);
}
mapping.findForward("edit");
}
15. Step 5. Conditionals make code
expensive to test
edit(mapping, form, request, response) {
person = Person.find(form.getId());
form = convert(person);
updateFormBean(mapping, request, form);
mapping.findForward("edit");
}
16. Step 6. All action methods have the
same four arguments
edit() {
person = Person.find(form.getId());
form = convert(person);
updateFormBean(mapping, request, form);
mapping.findForward("edit");
}
17. Step 7. Delegate object showing to
form
edit() {
person = Person.find(form.getId());
mapping.findForward("edit");
}
18. Step 8. Standard routing
edit() {
person = Person.find(form.getId());
}
Or Ruby
def edit
@person = Person.find(params[:id])
end
26. Starting Groovy
1. Download the .zip file from
http://groovy.codehaus.org and unzip it to
local drive
2. Create the GROOVY_HOME environment
variable and add $GROOVY_HOME/bin to
you path
3. type groovy -version
40. DSL
This is a really cool topic, where the stars are
began…
• A DSL allows expressions in a domain specific
manner
• Method pointers make this easy: def list = [] def
insert = list.&add insert ”beer" insert
”rock&roll"
42. At the end – NPE fighter in my team
infringementAction.setCustomsOffice(
versionedReplyInf != null ?
(versionedReplyInf.getReplyInf() != null ?
(versionedReplyInf.getReplyInf().getInf() != null ?
(versionedReplyInf.getReplyInf().getInf().getInf() != null ?
(versionedReplyInf.getReplyInf().getInf().getInf().
getCustomsOffice() != null ?
versionedReplyInf.getReplyInf().getInf().getInf().
getCustomsOffice()
: null) : null) : null) : null) : null);
43. At the end on Groovy
Safe navigation operator “?.”
infringementAction.setCustomsOffice(
versionedReplyInf?.getReplyInf()?.getInf()?.
getInf()?.getCustomsOffice())