groovy - Making Grails form development DRYer -
When using Grails, the GPP code looks like this to render each form field:
& lt; Tr class = "prop" & gt; & Lt; Td valign = "top" class = "name" & gt; & Lt; Label = "username" & gt; Login name: & lt; / Label & gt; & Lt; / Td> & Lt; Td valign = "top" class = "value $ {is the order (bean: person, area: 'username', 'errors')} & gt; & Lt; Input type = "text" id = "user name" name = "username" value = "$ {person.username .encodeAsHTML ()}" /> & Lt; / TD & gt; & Lt; / TR & gt; & Lt; Tr class = "prop" & gt; & Lt; Td valign = "top" class = "name" & gt; & Lt; Label = "userRealName" & gt; Full name: & lt; / Label & gt; & Lt; / Td> & Lt; Td valign = "top" class = "value $ {is errors (bean: person, area: 'userRealName', 'errors')}" & gt; & Lt; Input type = "text" id = "userRealName" name = "userRealName" value = "$ {person.userRealName ?. encodedHML ()}" /> & Lt; / TD & gt; & Lt; / TR & gt; & Lt; Tr class = "prop" & gt; & Lt; Td valign = "top" class = "name" & gt; For label = "passwd" & gt; Password: & lt; / Label & gt; & Lt; / Td> & Lt; Td valign = "top" class = "value $ {is errors (bean: person, field: 'passwd', 'errors')} & gt; & Lt; Input type = "password" id = "passwd" name = "passwd" value = "$ {person.passwd .encodeAsHTML ()}" /> & Lt; / TD & gt; & Lt; / TR & gt;
Note that approximately 5 lines of GSP / HTML code are being repeated for each form field. It does not seem very dry to me, and I am thinking that other people have found a better perspective?
I have got 2 plugins that try to solve this problem, and if anyone has any experience using any of these, I would be very interested to hear about them. Alternatively, if there are other solutions / plugins, please let me know.
Thank you. Don
Using this will become your code:
Bean : Bean Beename = "Person" & gt; & Lt; Bean: area property = "user name" label = "login name:" /> & Lt; Bean: Area property = "userRealName" label = "full name:" /> & Lt; Bean: Field Properties = "passwd" label = "Password:" /> & Lt; / Bean: withBean & gt;
Can you find a dryer solution?
Comments
Post a Comment