Grails 3.3.10 - DefaultGrailsDomainClass

62 views
Skip to first unread message

Pedro Gentil Soares

unread,
Oct 5, 2019, 12:50:05 PM10/5/19
to Grails Dev Discuss
I am migrating my application from version 2.5.6 to version 3.3.10.
How can I declare a variable of type DefaultGrailsDomainClass?
In the current version references to the org.grails.core.DefaultGrailsDomainClass class have been deprecated ...
For exaple:

...

def mainClass = Class.forName(domainName)
def mClass = Class.forName(matchClass)

DefaultGrailsDomainClass domainClass = new DefaultGrailsDomainClass (mainClass)
DefaultGrailsDomainClass domainMatch = new DefaultGrailsDomainClass (mClass)

....

Thanks alot

Jeff Scott Brown

unread,
Oct 7, 2019, 10:24:14 AM10/7/19
to Grails Dev Discuss
Can you summarize why you are wanting to create instances of
DefaultGrailsDomainClass? That answer may affect the recommendation.




JSB

--
Jeff Scott Brown
Partner and Practice Lead, Grails and Micronaut

Disruptive solutions for a connected world.™
http://objectcomputing.com

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

Pedro Gentil Soares

unread,
Oct 7, 2019, 10:09:46 PM10/7/19
to grails-de...@googlegroups.com
Hi Jeff,
Thank you for your prompt reply.
In my application built on Grails version 2.5.6, I use scaffolding template customizations. I created classes of services ("DomainNameDispService.groovy") for each of my domains explaining to grails how to render each screen responsible for CRUD including the various types of possible relationships between domains (1-n, n-n, ...).
For example, the method below is used to find out what class of service a particular domain is and return the value of the static variable "columnLink". Suppose we have the domain ItemCustoIniciativa:

@Transactional
class ItemCustoIniciativaDispService {

static def pHelpFiles = [:]; static Boolean doRemotePaginate = true
static Boolean hasTreeViewPresentation = false
static String columnLink = "descricao"
......

/**
* Created by PedroGentil on 03/12/2015.
*/
class TbcDomainService {
...
def static String getColumnLink (DefaultGrailsDomainClass domainClass) {

String lsRet = ""

String lsClassName = domainClass.getFullName() + "DispService"

def classDisp = Class.forName(lsClassName)

lsRet = classDisp."${'columnLink'}"

return lsRet

} // renderSearchingFields
....

In the scaffolding template "_insertInList.gsp" :

for (p in props) {

if (p.manyToMany) {
...
it << '                        <g:form>\n'

/* Campos do Formulário */

it << '<!-- <legend>Form</legend> -->\n'

colunLink = trustBC.TbcDomainService.getColumnLink(p?.getReferencedDomainClass())

it << ' <div class="span6 default-color3">\n'
it << ' <div class="control-group">\n'
it << ' <label class="control-label">&nbsp;'
it << ' <g:message code="' << colunLink.toString() << '.label" default="Buscar" locale="\${session.getAttribute(\'locale\')}"/>\n'
it << '</label><br/>\n'
...
In oter site:

for (p in props) {

if (p.isEmbedded()) {

def embeddedPropNames = pSearchingMap.get(p.getName())

def embeddedProps = p.component.properties.findAll { embeddedPropNames}

lsRet << renderEnbeddedProps (embeddedProps, domainClass) << "\n"
...
 

Thanks a lot!

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/6A9F8521-5F0D-495E-96E3-64750C1D1029%40objectcomputing.com.

Jeff Scott Brown

unread,
Oct 8, 2019, 6:25:17 AM10/8/19
to grails-de...@googlegroups.com

It still is not clear why you need to create an instance of DefaultGrailsDomainClass yourself. This whole thing could be done without referencing any of that but assuming there is some reason you want to use DefaultGrailsDomainClass you can retrieve the instance that the framework has already created for you by calling grailsApplication.getDomainClass(ItemCustoIniciativa.name).

However, it looks like the only reason you want the DefaultGrailsDomainClass is you want to ask it for the domain class’ name, which you can just get from the domain class.

I hope some of that helps.



JSB

Pedro Gentil Soares

unread,
Oct 8, 2019, 7:46:35 AM10/8/19
to grails-de...@googlegroups.com
Hi Jeff

Actually I don't want to create an element of type DefaultGrailsDomainClass. We need to access this domainClass element in various situations within the optimized scaffolding templates - as shown in the few examples I have presented. For example, the file "_insertInList.gsp" is part of the original Grails version 2.5.6 scaffolding templates.

One of my optimizations for "_insertInList.gsp" 's content is:


colunLink = trustBC.TbcDomainService.getColumnLink(p?.getReferencedDomainClass())

it << ' <div class="span6 default-color3">\n'
it << ' <div class="control-group">\n'
it << ' <label class="control-label">&nbsp;'
it << ' <g:message code="' << colunLink.toString() << '.label" default="Buscar" locale="\${session.getAttribute(\'locale\')}"/>\n'
it << '</label><br/>\n'
...

And so on.

Thanks again!




Jeff Scott Brown

unread,
Oct 9, 2019, 2:55:20 AM10/9/19
to grails-de...@googlegroups.com
On 8 Oct 2019, at 13:46, Pedro Gentil Soares wrote:

> Hi Jeff
>
> Actually I don't want to create an element of type
> DefaultGrailsDomainClass. Your original note included the following:

Your original note included the following:

def mainClass = Class.forName(domainName)
def mClass = Class.forName(matchClass)
DefaultGrailsDomainClass domainClass = new DefaultGrailsDomainClass
(mainClass)
DefaultGrailsDomainClass domainMatch = new DefaultGrailsDomainClass
(mClass)

That is why I thought you wanted to create instances of
DefaultGrailsDomainClass.

Pedro Gentil Soares

unread,
Oct 9, 2019, 8:18:00 AM10/9/19
to Grails Dev Discuss
Hi Jeff.
It is true. I apologize to you for not paying attention to the case.
Let's go: Since we have two class names, suppose 'org.Book' and 'org.Author' in a 1-n relationship. The idea is to be able to investigate the classes that correspond to the domains: make the classes talk about themselves, so to speak.
Thanks a lot.
Reply all
Reply to author
Forward
0 new messages