I’ve released another Grails plugin

Posted by: on Sep 18, 2009 | 10 Comments

Witness the power of the bean-fields plugin for Grails!

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

This will render input fields of the appropriate type, with sizes set according to the fields’ constraints, select field items from inList etc. It also renders label tags, errors local to the field, and required indicators.

You can customize the markup used for all this stuff, so that you get a consistent and noise-free rendering of fields across all your GSP views.

Please do check it out and let me know if you have any issues.

10 Comments

  1. Ted Naleid
    September 19, 2009

    Looks cool Marc, thanks for putting this together.

    A fellow coworker and I put something similar together at a previous workplace. The code was a little to specific to that company to release publicly unfortunately and I don’t have access to the source anymore.

    One enhancement that we had that might be nice for your plugin is an iterator that iterates through all of the fields on the bean, with an order that can be either passed in, by default it could respect the “constraints” order.

    Then you could pretty much replace the statically generated grails templates with a simple dynamic template that is customizable, but that automatically adjusts based on changes to the domain class.

    Reply
    • Marc Palmer
      September 20, 2009

      Hi Ted – yes this is already planned!

      I just had to publish the code I had as a) otherwise it would never happened and b) other projects I have depend on it!

      Reply
  2. Denis
    September 29, 2009

    Hi Marc.
    I wonder if you would add the ability to reset any field template to default ones or last used. It’ll need often when developer need to change field template only in the middle of the page or in GSP template which could appear in any part of GSP. I would suggest this:

    Thanks for great plugin.

    Reply
    • Marc Palmer
      September 29, 2009

      Denis – that could be a godd idea. I will jira it but it needs some more thought, eg it could be very confusing as to what it will revert to, and do we maintain an unlimited stack?

      I normally render GSP templates using g:render to set common field setups.

      Reply
  3. Sven
    September 29, 2009

    Awesome, Marc, thanks for developing this – it’s amazingly useful and speeds my Grails development even further. One extra feature that I’m always adding manually and that would clearly be the icing on the cake: kind of a descriptive line. Cool Web startups usually place those directly below the input in small print, i.e. “We need this for whatever reason”. Optionally the template could even hide it below some mouseover-help-icon.

    Thanks again for a great plugin!

    Reply
    • Marc Palmer
      September 29, 2009

      Sven you can easily do that with custom field templates that use with a code using a convention-based name using the bean + field name

      Reply
  4. Denis
    October 5, 2009

    Mark, thanks for response. I think the stack limit of 10 will be more than most needed. That’ll be a great feature.

    Continuing working with bean-field I noticed that nested withBean are not supported. Is there any way I can display validation errors of domains that are in relationship (one-to-one, one-to-many) with modified bean? For example:

    class DomainA {
    static hasOne = [ b:DomainB ]
    }

    class DomainB {
    String data
    static constraints {
    data(blank:false, inList:['first','second'])
    }
    }

    And the form is here http://www.everfall.com/paste/id.php?u3po01mh5mby
    I have no idea how to force error displaying in this case.

    Thanks for the great plugin.

    Reply
  5. Shaun
    August 22, 2010

    Marc – do you have any how-to docs? I just landed on this planet and am not sure how to use/implement your plugin. I think it will do what I need it to (manage default label property values?), but don’t know where to start.

    Appreciate any help,
    Shaun

    Reply
    • Marc Palmer
      August 24, 2010

      Shaun – did you follow the link to the plugin docs? they should answer most of your questions.

      Reply
  6. sudhir
    March 28, 2011

    Great plugin, discovered just recently, However the issue is, it doesn’t seem to support global custom field templates. Is there any way that would let me define custom templates for just once and then use it for all requests. I wouldn’t want to customize my template for each request.

    Instead of customizing it in GSP, there could be a way to customize them in configuration, or just have partials(_textField.gsp) for each tag.

    Answer my question of global templates

    But, really helpful plugin.
    Thanks

    Reply

Leave a Reply