Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:55:23+00:00 2026-06-16T09:55:23+00:00

I’m using Grails 2.1.1 with mongodb plugin. I have problem with changing order of

  • 0

I’m using Grails 2.1.1 with mongodb plugin. I have problem with changing order of columns in generated list. As grails scaffolding guide says you need only properly order attributes in contraints block.

My domain:

class Section {

String idName
String visible
String required
String name
String bold

static embedded = ['question']

List<Question> questions
static hasMany = [questions : Question]

static constraints = {
    idName (blank: false)
    name (blank: false)
    visible (blank: false)
    required (blank: false)
    bold (blank: false)
}

@Override
public String toString() {
    name
}
}

but columns are still ordered alphabetically. I’m using static scaffolding, so after changes in constraints i use grails generate-all * command and override all files.

And yes, I tried cleaning and compiling code, also cleaning and restarting server (this integrated with STS) and cleaning browser cache. Is there problem with mongo database (hibernate plugin is uninstalled)?

After that I also installed grails templates. In list.gsp there is line with sorting attributes:

Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[]))

Any idea how can i change this to get working order that I set in constraints?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:55:25+00:00Added an answer on June 16, 2026 at 9:55 am

    A jira issue should be filled. If one looks at
    https://github.com/grails/grails-core/blob/master/grails-crud/src/main/groovy/org/codehaus/groovy/grails/scaffolding/DefaultGrailsTemplateGenerator.groovy

     void generateView(GrailsDomainClass domainClass, String viewName, Writer out) {
        def templateText = getTemplateText("${viewName}.gsp")
    
        if (templateText) {
            def t = engine.createTemplate(templateText)
            def multiPart = domainClass.properties.find {it.type == ([] as Byte[]).class || it.type == ([] as byte[]).class}
    
            boolean hasHibernate = pluginManager?.hasGrailsPlugin('hibernate')
            def packageName = domainClass.packageName ? "<%@ page import=\"${domainClass.fullName}\" %>" : ""
            def binding = [pluginManager: pluginManager,
                    packageName: packageName,
                    domainClass: domainClass,
                    multiPart: multiPart,
                    className: domainClass.shortName,
                    propertyName:  getPropertyName(domainClass),
                    renderEditor: renderEditor,
                    comparator: hasHibernate ? DomainClassPropertyComparator : SimpleDomainClassPropertyComparator]
    
            t.make(binding).writeTo(out)
        }
    
    }
    

    It is clear that the call generate views decides to use SimpleDomainClassPropertyComparator. Grails was originally built to depend on hibernate. Over the last couple of years, the world has been using additional persistance mechanisms. If one looks at DomainClassPropertyComparator, there is no dependency on hibernate. I feel the code should test if the domainObject “hasConstraints” to decide which comparator to use or simple use DomainClassPropertyComparator by default. Its behavior is the same if no constraints are found. The call to “hasHibernate” should not be needed by DefaultGrailsTemplateGenerator.

    As a work around, you can install the scaffolding templates, edit _form.gsp and change the comparator it is using to DomainClassPropertyComparator
    e.g. my _form.gsp

        <%=packageName%>
    <% import grails.persistence.Event %>
    <% import org.codehaus.groovy.grails.scaffolding.DomainClassPropertyComparator %>
    
    
    <%  excludedProps = Event.allEvents.toList() << 'version' << 'dateCreated' << 'lastUpdated'
        persistentPropNames = domainClass.persistentProperties*.name
        boolean hasHibernate = pluginManager?.hasGrailsPlugin('hibernate')
        if (hasHibernate && org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.getMapping(domainClass)?.identity?.generator == 'assigned') {
            persistentPropNames << domainClass.identifier.name
        }
    
    DomainClassPropertyComparator mattsComparator = new DomainClassPropertyComparator(domainClass)
    comparator = mattsComparator
    
    props = domainClass.properties.findAll { persistentPropNames.contains(it.name) && !excludedProps.contains(it.name) }
        Collections.sort(props, comparator)
        for (p in props) {
            if (p.embedded) {
                def embeddedPropNames = p.component.persistentProperties*.name
                def embeddedProps = p.component.properties.findAll { embeddedPropNames.contains(it.name) && !excludedProps.contains(it.name) }
                Collections.sort(embeddedProps, comparator)
                %><fieldset class="embedded"><legend><g:message code="${domainClass.propertyName}.${p.name}.label" default="${p.naturalName}" /></legend><%
                    for (ep in p.component.properties) {
                        renderFieldForProperty(ep, p.component, "${p.name}.")
                    }
                %></fieldset><%
            } else {
                renderFieldForProperty(p, domainClass)
            }
        }
    
    private renderFieldForProperty(p, owningClass, prefix = "") {
        boolean hasHibernate = pluginManager?.hasGrailsPlugin('hibernate')
        boolean display = true
        boolean required = false
        if (hasHibernate) {
            cp = owningClass.constrainedProperties[p.name]
            display = (cp ? cp.display : true)
            required = (cp ? !(cp.propertyType in [boolean, Boolean]) && !cp.nullable && (cp.propertyType != String || !cp.blank) : false)
        }
        if (display) { %>
    <div class="fieldcontain \${hasErrors(bean: ${propertyName}, field: '${prefix}${p.name}', 'error')} ${required ? 'required' : ''}">
        <label for="${prefix}${p.name}">
            <g:message code="${domainClass.propertyName}.${prefix}${p.name}.label" default="${p.naturalName}" />
            <% if (required) { %><span class="required-indicator">*</span><% } %>
        </label>
        ${renderEditor(p)}
    </div>
    <%  }   } %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.