Grails controls the scaffold of the query scope
Last Update:2018-07-23
Source: Internet
Author: User
Generated by scaffold in Customercontroller
Java code static allowedproperties = [' name ', ' address ', ' telephone ', ' Postcode '] def list = { params.max = math.min (Params.max ? params.int (' Max ') : 10, 100) def customerInstanceList, customerInstanceTotal if (params?). Searchvalue && allowedproperties.contains (params?). Searchkey)) { def c = Customer.createcriteria () customerinstancelist = c.list (max: params.max, offset: params.offset?:0) { ilike ( params.searchkey, "%" + params.searchValue + "%") &nbsP; eq ("deleted", false) } customerinstancetotal = customerinstancelist.totalcount } else { customerInstanceList = Customer.findallbydeleted (false, params) Customerinstancetotal = customer.countbydeleted (false) } [customerinstancelist: customerinstancelist, customerinstancetotal: customerInstanceTotal] }
The corresponding controller-scaffold sections are:
Java code <% excludedprops = event.allevents.tolist () << ' id ' << ' version ' << ' dateCreated ' << ' LastUpdated ' << ' deleted ' << ' Itemorder ' << ' Memo ' allowedNames = domainClass.persistentProperties*.name props = domainclass.properties.findall { allowednames.contains (It.name) && !excludedprops.contains (It.name) && ! Collection.isassignablefrom (It.type) } collections.sort (props, Comparator.constructors[0].newinstance ([domainclass] as object[]) def propNames = [] props.name.each {propnames.add "'" +it+ "'"} %> STATIC&Nbsp;allowedproperties = <%=propnames %> def list = { params.max = math.min (params.max ? params.int (' Max ') : 10, 100) def ${propertyname}list, ${ propertyname}total if (params?). Searchvalue && allowedproperties.contains (params?). Searchkey)) { def c = ${ Classname}.createcriteria () ${propertyname}list = c.list (max: params.max, offset: params.offset?:0) { ilike ( params.searchkey, "%" + params.searchValue + "%") EQ ("deleted", false) } ${propertyname}total = ${propertyname}list.totalcount } else { ${propertyname}list = ${classname}.findallbydeleted (false, params) ${propertyname}total = ${classname}.countbydeleted (False) } [${propertyname}list: ${ propertyname}list, ${propertyname}total: ${propertyname}total] }
The list page is generated by scaffold
Java code <g:form action= "list" method= "POST" usetoken= "true" > <g:select name= "Searchkey" from= "${customerco Ntroller.allowedProperties.toList ()} "value=" ${searchkey} "optionvalue=" ${{message (code: ' Customer. ') +it+ '. Label ', Default:message (code: ' DomainProperty. ') +it+ '. Label ', Default:it)}} "/> <input type=" text "name=" Searchvalue "value=" ${params?. Searchvalue} "/> </g:form>
The corresponding scaffold-list sections are:
Java code <g:select name= "Searchkey" from= "\${${domainclass.fullname}controller.allowedproperties.tolist ()}" value = "\${searchkey}" optionvalue= "\${{message (Code: ' ${domainclass.propertyname}. ') +it+ '. Label ', Default:message (code: ' DomainProperty. ') +it+ '. Label ', Default:it)}} "/>
i18n Append
Java code domainproperty.name.label= name ....