Re: [Model-Glue] Issue with MG - Struct Returns Empty

22 views
Skip to first unread message

Dan Wilson

unread,
Jul 17, 2012, 4:53:52 PM7/17/12
to model...@googlegroups.com
Usually, when this happens, it's because you aren't accessing the controller function.

There are two common reasons for this. Either your application is set to not reload, and you've added the controller stuff without manually reloading your application, or you aren't calling the controller method to begin with.

The easiest way to figure this out is to turn reload on and also turn debug on in your ColdSpring.xml. See below for a snippet:

<bean id="modelglue.modelGlueConfiguration" class="ModelGlue.gesture.configuration.ModelGlueConfiguration">

<!-- Be sure to change these to false when you go to production! -->
<property name="reload"><value>true</value></property>
<property name="debug"><value>true</value></property>


You will need to manually reload your application for the changes to be picked up. Once you do, you should have a bunch of debug messages below. Look for the name of the message that you have in your event that is linked to the getClient() method in your controller. If it isn't there, you can start to match up the Message name, with the message-listener message attribute in your controller.xml declaration. 

If you haven't figured it out by then, post the ModelGlue.xml configuration on http://pastebin.com and post the URL of the pastebin back to this thread.


DW




On Tue, Jul 17, 2012 at 4:33 PM, Craig Derington <cderi...@gmail.com> wrote:
I'm new to MG3 and have been trying to learn the framework by reviewing the docs and other developers code, specifically LHP.  I still have a ways to go to get up to speed .  I have run into a frustrating issue that I can not resolve.  Any help would certainly be appreciated.

A simple client table in DB.

The event page.clients returns the full list of clients properly.  No problem there.  However, when I link from page.clients to page.client and pass the clientID to the ClientController, my struct is always empty.

page.client
<cfset client = event.getValue("client") />
<cfdump var="#client#" label="clientDetails">

ClientController

<cffunction name="getClient" access="public" output="false">
   <cfargument name="event" type="any">
   <cfset var clientid = arguments.event.getValue("clientID") />
   <cfset var client = beans.clientService.getClient(clientID) />

   <cfset arguments.event.setValue("client", client)>
</cffunction>


Model

ClientService

<cffunction name="getClient" access="public" returntype="any" output="false" hint="Gets a client bean based on the client's ID.">
   <cfargument name="clientID" type="any" required="false">
<cfif structKeyExists(arguments,"clientID") and arguments.clientID NEQ 0>
<cfreturn variables.gateway.getClient(arguments.clientID)>
<cfelse>
<cfreturn variables.gateway.newClient()>
</cfif>
</cffunction>


ClientGateway

<cffunction name="getClient" access="public" returntype="clientBean" output="false">
<cfargument name="clientID" type="any" required="true">
<cfset var cBean = createObject("component", "ClientBean") />
<cfset var clientData = "" />
<cfquery name="clientData" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
SELECT clientID, clientname, clientaddress, clientcity, clientstate, clientzipcode, clientphonenumber, clientdateadded
 FROM dbo.clients
WHERE clientid = <cfqueryparam value="#arguments.clientID#" />
</cfquery>
<cfif clientData.recordCount>
<cfset cBean.setClientID(clientData.clientid) />
<cfset cBean.setClientName( clientData.clientname) />
<cfset cBean.setClientAddress(clientData.clientaddress) />
<cfset cBean.setClientCity(clientData.clientcity) />
<cfset cBean.setclientstate(clientData.clientstate) />
<cfset cBean.setClientZipcode(clientData.clientzipcode) />
<cfset cbean.setClientPhoneNumber(clientData.clientphonenumber) />
<cfset cbean.setClientDateAdded(clientData.clientdateadded) />
</cfif>
<cfset cBean.setConfig(variables.config) />
<cfreturn cBean>
</cffunction>


ClientBean

<cfset variables.instance = structNew() />
<cfset variables.instance.clientid = 0 />
<cfset variables.instance.clientname = "" />
<cfset variables.instance.clientaddress = "" />
<cfset variables.instance.clientcity = "" />
<cfset variables.instance.clientstate = "" />
<cfset variables.instance.clientzipcode = "" />
<cfset variables.instance.clientdateadded = "" />

{{{  setting and getting all columns }}}

All the accessors are referenced... followed by the instance
<cffunction name="getInstance" returntype="struct" access="public" output="false">
<cfreturn duplicate(variables.instance)>
</cffunction>
<cffunction name="setConfig" returntype="void" access="public" output="false" hint="Used to allow beans to inject settings">
<cfargument name="config" type="any" required="true">
<cfset variables.config = arguments.config>
</cffunction>

I have made a dozen changes and I can not get the specific client details returned to the page.client event.  I try and dump the result and it returns 
clientDetails - struct [empty]

Frustrated.

My user model is working fine and is almost the exact same code...

--
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."

Ezra Parker

unread,
Jul 17, 2012, 7:27:00 PM7/17/12
to model...@googlegroups.com
If I'm not mistaken, this actually isn't a Model-Glue issue, but a problem due to a scope conflict.

When doing this:


<cfset client = event.getValue("client") />
<cfdump var="#client#" label="clientDetails">

You are creating a variable named "client" in the variables scope of the page, but the dump is referencing the client scope (which in this case is an empty struct). If you dump "variables.client" instead, you should see your object.

That said, I would strongly recommend against using variable names that are also CF scopes (client, session, url, etc.), as that can often result in exactly this kind of confusing behavior.

--
Ezra Parker

Dan Wilson

unread,
Jul 17, 2012, 7:35:53 PM7/17/12
to model...@googlegroups.com

Nice catch Ezra, that does look like the issue...

Dw

Craig Derington

unread,
Jul 18, 2012, 9:59:13 AM7/18/12
to model...@googlegroups.com
Thank you, Ezra.  That was the problem.  I renamed the variable customer and it works properly.  I did not know the word "client" was reserved.  I have used this word many times before in Non-OO environments and never had a problem.

Thanks again for your help.  Very much appreciated.


Craig

>> 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."
>
> --
> 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

Craig Derington

unread,
Jul 18, 2012, 10:00:27 AM7/18/12
to model...@googlegroups.com
Thanks for your help, Dan.  It's working now...

Dan Wilson

unread,
Jul 18, 2012, 10:09:02 AM7/18/12
to model...@googlegroups.com
Craig,

Client is not a reserved word in Model Glue, nor in OO. It refers to the client scope.

Just for fun, open a test page OUTSIDE of the modelglue context and dump the client scope. 
Then, in the same page, Do this: <cfset Client.ModelGlue = "Rocks" />

Then, in another page, dump the client scope. You should see the value you entered on the previous page. 


When you enable client variables for an application, you can use them to keep track of long-term information that is associated with a particular client.

Client variables must be simple data types: strings, numbers, lists, Booleans, or date and time values. They cannot be arrays, record sets, XML objects, query objects, or other objects.

--
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

Craig Derington

unread,
Jul 18, 2012, 11:22:49 AM7/18/12
to model...@googlegroups.com
Thanks Dan.  That helps explain the variable scope.

Muhammad Amir

unread,
Apr 8, 2013, 7:43:05 AM4/8/13
to model...@googlegroups.com

Hi dear,

Can some send me sample application code which covers Model + controller +View with very less code so I can understand and I can do some practice.

 Highly appreciated

M.A



On Wed, Jul 18, 2012 at 7:22 PM, Craig Derington <cderi...@gmail.com> wrote:
Thanks Dan.  That helps explain the variable scope.

--

Dan Skaggs

unread,
Apr 8, 2013, 8:28:45 AM4/8/13
to model...@googlegroups.com
You might want to look at our "helloWorld" sample app. All our sample apps reside in a different repository.  You can find them here:
 
Dan
 
------ Original Message ------
From: "Muhammad Amir" <onlya...@gmail.com>
Sent: 4/8/2013 6:43:05 AM
Subject: Re: [Model-Glue] Issue with MG - Struct Returns Empty

Hi dear,

Can some send me sample application code which covers Model + controller +View with very less code so I can understand and I can do some practice.

 Highly appreciated

M.A

On Wed, Jul 18, 2012 at 7:22 PM, Craig Derington <cderi...@gmail.com> wrote:
Thanks Dan.  That helps explain the variable scope.

--
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

For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

--
--
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
---
You received this message because you are subscribed to the Google Groups "model-glue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to model-glue+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Xeondxb

unread,
Apr 8, 2013, 9:05:33 AM4/8/13
to model...@googlegroups.com

hi dan,

 

thanks for reply, i just checked your "helloworld" app. This sample app   Model/ folder also empty i need something where your using little business logic in model .

Thanks

Regards,

M.A

Dan Wilson

unread,
Apr 8, 2013, 9:19:50 AM4/8/13
to model...@googlegroups.com
I'm guessing the next best thing is the PlantOMatic training application and course. You can find it here:

https://github.com/modelglue/modelglue-framework/wiki/Training


DW

Monday, April 08, 2013 9:05 AM

hi dan,

 

thanks for reply, i just checked your "helloworld" app. This sample app   Model/ folder also empty i need something where your using little business logic in model .

Thanks

Regards,

M.A

 

From: model...@googlegroups.com [mailto:model...@googlegroups.com] On Behalf Of Dan Skaggs
Sent: Monday, April 08, 2013 4:29 PM
To: model...@googlegroups.com
Subject: Re[2]: [Model-Glue] Issue with MG - Struct Returns Empty

 

You might want to look at our "helloWorld" sample app. All our sample apps reside in a different repository.  You can find them here:

 

Dan

 

------ Original Message ------

From: "Muhammad Amir" <onlya...@gmail.com>

Sent: 4/8/2013 6:43:05 AM

Subject: Re: [Model-Glue] Issue with MG - Struct Returns Empty

--

Monday, April 08, 2013 8:28 AM
Monday, April 08, 2013 7:43 AM

Hi dear,

Can some send me sample application code which covers Model + controller +View with very less code so I can understand and I can do some practice.

 Highly appreciated

M.A




Reply all
Reply to author
Forward
0 new messages