21. Mai 2012

Bean Fields for Grails renders form fields easily

Bean Fields, a new plugin for Grails, provides a suite of tags for rendering form fields for domain and command objects. As the developers claim, it takes the pain, boredom and scope for error away.

Out of the box it:

  • renders a field using a UI element appropriate for the property type. Constraints are used to set maximum lengths etc.
  • automatically renders
  • renders “required” indicators if the field is nullable:false and/or blank:false
  • renders errors adjacent to the field that had the error
  • renders the current value as appropriate

Here’s an example of how you can render all this for a bunch of bean properties:

<bean:withBean beanName="form">
    <bean:field property="firstName">
    <bean:field property="lastName">
    <bean:field property="company">
    <bean:field property="email">
</bean:withBean>

You can find more elaborate examples as well as instructions for use on the plugin page.

Diese Beiträge könnten Sie noch interessieren:

Ihre Meinung ist uns wichtig

*