Changeset 409

Show
Ignore:
Timestamp:
11-05-10 16:47:22 (4 years ago)
Author:
keesvb
Message:

OK, that refactoring was too enthusiastic, switching back getField() to pure TemplateField? collections fixes the strange TemplateFieldListItem?.id bugs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r406 r409  
    258258         * @throws NoSuchFieldException If the field is not found or the field type is not supported 
    259259         */ 
    260         private static def getField(Collection fieldsCollection, String fieldName) { 
     260        private static TemplateField getField(List<TemplateField> fieldsCollection, String fieldName) { 
    261261                // escape the fieldName for easy matching 
    262262                // (such escaped names are commonly used 
     
    265265 
    266266                // Find the target template field, if not found, throw an error 
    267                 def field = fieldsCollection.find { it.name.toLowerCase().replaceAll("([^a-z0-9])", "_") == escapedLowerCaseFieldName } 
     267                TemplateField field = fieldsCollection.find { it.name.toLowerCase().replaceAll("([^a-z0-9])", "_") == escapedLowerCaseFieldName } 
    268268 
    269269                if (field) { 
     
    325325                // Convenience setter for template string list fields: find TemplateFieldListItem by name 
    326326                if (field.type == TemplateFieldType.STRINGLIST && value && value.class == String) { 
    327                         value = getField(field.listEntries,value).name 
    328                         println value 
     327                        // Kees insensitive pattern matching ;) 
     328                        def escapedLowerCaseValue = value.toLowerCase().replaceAll("([^a-z0-9])", "_") 
     329                        value = field.listEntries.find { 
     330                                it.name.toLowerCase().replaceAll("([^a-z0-9])", "_") == escapedLowerCaseValue 
     331                        } 
    329332                } 
    330333