Changeset 343 for trunk/grails-app/taglib/CustomTagLib.groovy
- Timestamp:
- Feb 10, 2010, 2:49:13 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/taglib/CustomTagLib.groovy
r303 r343 16 16 * To map the selected ids to corresponding domain objects, 17 17 * an additional set method is required in the containing domain class: 18 * // This additional setter is used to convert the checkBoxList string 18 * // This additional setter is used to convert the checkBoxList string or string array 19 19 * // of ids selected to the corresponding domain objects. 20 20 * public void setAssetSubItemsFromCheckBoxList(ids) { 21 21 * def idList = [] 22 * ids.each() { 23 * if(it.isInteger()) 24 * idList << it.toInteger() 22 * if(ids instanceof String) { 23 * if(ids.isInteger()) 24 * idList << ids.toInteger() 25 * } 26 * else { 27 * ids.each() { 28 * if(it.isInteger()) 29 * idList << it.toInteger() 30 * } 25 31 * } 26 32 * this.assetSubItems = idList.collect { AssetSubItem.get( it ) } … … 35 41 * value - the current value. 36 42 * optionKey - the key to use. 37 * displayFields - (optional) available options are 'id' and 'name', defaults to the objects toString(). 43 * sortBy - (optional) the attribute to sort the from list by. 44 * displayFields - (optional) defaults to the objects toString() 45 * displayFieldsSeparator - (optional) defaults to a space. 38 46 * linkController - (optional, requires linkAction.) the controller to use for a link to the objects in the checkBoxList. 39 47 * linkAction - (optional, requires linkController.) the action to use for a link to the objects in the checkBoxList. … … 45 53 * value="${assetInstance?.assetSubItems.collect{it.id}}" 46 54 * optionKey="id" 55 * sortBy="description" 47 56 * displayFields="['id', 'name']" 57 * displayFieldsSeparator=', ' 48 58 * linkController="assetSubItemDetailed" 49 59 * linkAction="show"/> … … 59 69 def isChecked, ht, wd, style, html 60 70 71 def sortBy = attrs.sortBy 61 72 def displayFields = attrs.displayFields 73 def displayFieldsSeparator = attrs.displayFieldsSeparator ?: ' ' 62 74 def linkController = attrs.linkController 63 75 def linkAction = attrs.linkAction … … 81 93 out << html 82 94 95 if(sortBy) 96 from.sort { p1, p2 -> p1[sortBy].compareToIgnoreCase(p2[sortBy]) } 97 83 98 from.each { obj -> 84 99 85 100 displayValue = " " 86 101 87 if( displayFields?.contains("id") )88 displayValue += obj.id + " - "89 90 102 if(linkController && linkAction) 91 103 displayValue += "<a href=\"${createLink(controller: linkController, action: linkAction, id: obj.id).encodeAsHTML()}\">" 92 104 93 if(displayFields ?.contains("name")) {94 displayValue += obj.name105 if(displayFields) { 106 displayValue += displayFields.collect { obj[it] }.join(displayFieldsSeparator) 95 107 } 96 else displayValue += obj 108 else displayValue += obj // use the obj's default toString() 97 109 98 110 if(linkController && linkAction) 99 displayValue += '</a>'111 displayValue += "</a>" 100 112 101 113 // if we wanted to select the checkbox using a click anywhere on the label (also hover effect)
Note: See TracChangeset
for help on using the changeset viewer.