In this article we will learn about some of the frequently asked Ruby programming questions in technical like “comparator.constructors[0].newInstance([domainClass] in grails 3” Code Answer. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error handling in Ruby is simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Ruby. Below are some solution about “comparator.constructors[0].newInstance([domainClass] in grails 3” Code Answer.
comparator.constructors[0].newInstance([domainClass] in grails 3
xxxxxxxxxx
1
<table class="table table-striped">
2
<thead>
3
<tr>
4
<%
5
def grailsApplication = grails.util.Holders.grailsApplication
6
domainObjetc = grailsApplication.domainClasses.find { it.clazz.simpleName == className }.clazz.newInstance()
7
domainClass= grailsApplication.getDomainClass(domainObjetc.class.name)
8
excludedProps = grails.persistence.Event.allEvents.toList() << 'id' << 'version'
9
allowedNames = domainClass.persistentProperties*.name << 'dateCreated' << 'lastUpdated'
10
props = domainClass.properties.findAll { allowedNames.contains(it.name) && !excludedProps.contains(it.name) && it.type != null && !Collection.isAssignableFrom(it.type) }
11
comparator = new org.grails.validation.DomainClassPropertyComparator(domainClass)
12
Collections.sort(props, comparator)
13
props.eachWithIndex { p, i ->
14
if (i < 6) {
15
if (p.isAssociation()) {
16
%><th class="header"><g:message code="${domainClass.propertyName}.${p.name}.label" default="${p.naturalName}" /></th><%
17
} else {
18
%><g:sortableColumn property="${p.name}" title="${message(code: '${domainClass.propertyName}.${p.name}.label', default: '${p.naturalName}')}" /><%
19
}
20
}
21
}%>
22
<th></th>
23
</tr>
24
</thead>
25
<tbody>
26
<g:each in="${${propertyName}List}" var="${propertyName}">
27
<tr>
28
<% props.eachWithIndex { p, i ->
29
if (i < 6) {
30
if (p.type == Boolean || p.type == boolean) { %>
31
<td><g:formatBoolean boolean="${${propertyName}.${p.name}}" /></td>
32
<% } else if (p.type == Date || p.type == java.sql.Date || p.type == java.sql.Time || p.type == Calendar) { %>
33
<td><g:formatDate date="${${propertyName}.${p.name}}" /></td>
34
<% } else { %>
35
<td>${fieldValue(bean: ${propertyName}, field: "${p.name}")}</td>
36
<% } } } %>
37
<td class="link">
38
<div class="btn-group btn-group-xs">
39
<g:link action="show" id="${${propertyName}.id}" class="btn btn-primary btn-sm" role="button">
40
<span class="glyphicon glyphicon-eye-open"></span>
41
<g:message code="default.button.show.label" default="Show" />
42
</g:link>
43
<g:link action="edit" id="${${propertyName}.id}" class="btn btn-primary btn-sm" role="button">
44
<span class="glyphicon glyphicon-pencil"></span>
45
<g:message code="default.button.edit.label" default="Edit" />
46
</g:link>
47
</div>
48
</td>
49
</tr>
50
</g:each>
51
</tbody>
52
</table>