MG Scaffolding List array instead of query?

25 views
Skip to first unread message

marc

unread,
Jan 26, 2012, 10:21:18 AM1/26/12
to model...@googlegroups.com
Hi,

I am playing with ModelGlue scaffolding feature with CF9 Hibernate ORM. I find that the List event handler returns a query result set of all my records in table, whereas cf9 EntityLoad() returns an array of entiities. When I look in the MG framework where it executes List() , I see that the handler initially retrieves an array of entities via EntityLoad(). Then MG converts the returned array with objects to a query with EntitytoQuery().

I'd rather have an array of objects than a simple query resultset. Can I change MG so that this behaviour is configurable?

Here is the MG code where a list of objects is retrieved and then convreted to a struct:

in /ModelGlue/gesture/modules/orm/cform/cfORMService.cfc

    any function list(required string entityName, struct filterCriteria=StructNew(), string sortOrder="", string returnType="query") {
        var list = EntityLoad(arguments.entityName,arguments.filterCriteria,arguments.sortOrder);
        if (arguments.returnType eq "query") {
            list = EntitytoQuery(list);
        }
        return list;
    }

As far as I can see the argument returnType is not specified in the calling component (/ModelGlue/gesture/modules/orm/cform/cfORMAdapter.cfc) so it always defaults to "query".

Marc

Matt Quackenbush

unread,
Jan 26, 2012, 10:24:51 AM1/26/12
to model...@googlegroups.com
Not sure where the code calls on list(), but if you provide `returnType="ANYTHING_BUT_QUERY"` then you will be delivered the array of entities.

So, check farther up the execution chain and see where you can pass, say, `returnType="array"`, and you should be all set.

--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
 
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Dan Wilson

unread,
Jan 26, 2012, 10:32:06 AM1/26/12
to model...@googlegroups.com
Keep in mind, your view will need to deal with an array of objects now, so you'll have to update that.

This article talks about how to change the generated Model Glue code:






DW

--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
 
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en



--
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."

Chris Blackwell

unread,
Jan 26, 2012, 10:39:42 AM1/26/12
to model...@googlegroups.com
You could create a component that extends ModelGlue.gesture.modules.orm.cform.cfORMService overriding the list() method to return an array of entities by default.

Then tell ModelGlue to use your service rather than its own in your ColdSpring.xml 

<bean id="ormService" class="model.service.myCfOrmService" />

But, as Dan mentioned, this will break the default views that are generated.

Chris

Dan Wilson

unread,
Jan 26, 2012, 10:46:41 AM1/26/12
to model...@googlegroups.com
Yup... though it bears mentioning it is very easy to change the patterns ModelGlue uses for scaffolding. So there is no need to update tons of files.



You can see how to alter the provided scaffolds. You can also make your own scaffold pattern and call it something else. After you register it with Model Glue, you can call it like this:

MG Code:
<scaffold object="Post" type="Delete,Grid,Edit"/>

ColdSpring Code:

<bean id="ScaffoldTemplate.Grid"  factory-bean="modelglue.scaffoldManager" factory-method="addScaffoldTemplate" lazy-init="false">  
<constructor-arg name="scaffoldBeanRegistry">  
<list>
<ref bean="mgtest.scaffoldTemplate.Grid" />
</list> 
</constructor-arg>  
</bean>
<bean id="mgtest.scaffoldTemplate.Grid" class="coldspring.beans.factory.config.MapFactoryBean">
<property name="SourceMap">
<map>
<entry key="class"><value>mgtest.model.Grid</value></entry>
<event key="hasXMLGeneration"><value>true</value></event>
<event key="hasViewGeneration"><value>true</value></event>
<entry key="prefix"><value>Grid.</value></entry>
<entry key="suffix"><value>.cfm</value></entry>
</map>
</property>
</bean>



Note, the class parameter will point to your CFC in your project (or elsewhere) you made for your generational pattern. I recommend starting (not altering) the ones that ship with Model Glue and placing your altered CFC inside your project.


DW




Dan Wilson

unread,
Jan 26, 2012, 11:08:47 AM1/26/12
to model...@googlegroups.com
I documented this on the training class wiki section:



It's under Bonus Points. Hopefully the process will be clearer than my previous email.


DW

Marc Bakker

unread,
Jan 26, 2012, 12:03:49 PM1/26/12
to model...@googlegroups.com
Hi Dan,

looks super clear but I keep; getting a query instead of a ;list of entities...
here's what I did

copy /ModelGlue/gesture/modules/scaffold/beans/plain/List.cfc
to
/CFlab/Application/model/scaffoldTemplates/List.cfc

add a mapping /scaffoldTemplates in /Application.cfc that points to F:/www/CFlab/Application/model/scaffoldTemplates/

change
List.cfc:

    <cfset xml = xml & '>
            <broadcasts>
                <message name="ModelGlue.genericList">
                    <argument name="criteria" value="" />
                    <argument name="object" value="#arguments.alias#" />
                    <argument name="queryName" value="#arguments.alias#Query" />
                </message>
            </broadcasts>

by adding

                    <argument name="returnType" value="array" />


to the <broadcasts> section

so I should get no query resultset from the List method

in coldspring.xml add this to point to the new modifield List.cfc:

<bean id="modelglue.scaffoldType.List" class="coldspring.beans.factory.config.MapFactoryBean">
    <property name="SourceMap">
        <map>
            <entry key="class"><value>scaffoldTemplates.List</value></entry>

            <event key="hasXMLGeneration"><value>true</value></event>
            <event key="hasViewGeneration"><value>true</value></event>
            <entry key="prefix"><value>List.</value></entry>

            <entry key="suffix"><value>.cfm</value></entry>
        </map>
    </property>
</bean>

all I changed it this line <entry key="class"><value>CFLab.Application.model.scaffoldTemplates.List</value></entry> to point to the modifield List.cfc.

It looks like MG is not picking up on the new List.cfc. Whatever I put in it (e.g. <cfabort>),has no consequences.
Is the use of the mapping "/scaffoldTemplates" correct?

Btw, in Coldspring.xml  rescaffold=true, reload=true

Marc
Met vriendelijke groet,

Marc Bakker

Dan Wilson

unread,
Jan 26, 2012, 12:19:31 PM1/26/12
to model...@googlegroups.com
Where are you putting your cfabort?

Turn on the MG debugging and see if anything helpful shows up in there.


DW

Chris Blackwell

unread,
Jan 26, 2012, 12:31:02 PM1/26/12
to model...@googlegroups.com
ModelGlue.GenericList doesn't pass your returnType argument through to the ormService, so its always going to return a query.

I think, if you want ormService to return an array of entities (without altering MG internals) you'll need to override the ormService bean as I described

Chris

Marc Bakker

unread,
Jan 26, 2012, 6:05:41 PM1/26/12
to model...@googlegroups.com
Yes! This works.

I created a copy of the /ModelGlue/gesture/modules/orm/cform/cfORMService.cfc, added extends="ModelGlue.gesture.modules.orm.cform.cfORMService", removed all methods except List() which I adapted (returnType="array". Then I added this in my projects ColdSpring.xml:

<bean id="ormService.cfORM" class="services.cfORMService" />

(note the id: "ormService.cfORM", it's not "ormService").

Now MG is using the modified cfORMService instead of it's own.

Thanks all!

Marc
Reply all
Reply to author
Forward
0 new messages