Making Grails form development DRYer

后端 未结 3 1009
耶瑟儿~
耶瑟儿~ 2021-02-10 05:48

When using Grails, the GSP code to render each form field looks something like this:


  

        
相关标签:
3条回答
  • 2021-02-10 06:00

    Using the bean-field plugin. Your code will become:

    <bean:withBean beanName="person">
        <bean:field property="username" label="Login Name:"/>
        <bean:field property="userRealName" label="Full Name:"/>
        <bean:field property="passwd" label="Password:"/>
    </bean:withBean>
    

    Can you find a DRYer solution?

    0 讨论(0)
  • 2021-02-10 06:10

    Yes, bean-fields plugin is very DRY… your 20 lines can be replaced with one line:

    <bean:form beanName="person" properties="username, userRealName, passwd”/>
    

    (Assuming you have i18n properties set)

    0 讨论(0)
  • 2021-02-10 06:11

    For those who read this thread in future - For grails 2.x branch Grails fields plugin is recommended over bean fields, its actually successor of bean-fields and provides flexibility to override default templates

    0 讨论(0)
提交回复
热议问题