Viewstate not deleting values

4 views
Skip to first unread message

byron

unread,
Feb 12, 2008, 6:47:18 PM2/12/08
to model-glue
I have an app running MG 2.0 (2.0.304), Coldspring, and Reactor
(428). I'm running into the following problem.

1) enter a new participant record using:
(event=participant.edit&ID=0) that fires a message listener that
executes a (participantRecord.load(ID=0).
2) upon committing, I redirect to the list of particpants
(name="commit" redirect="true" preservestate="false")
3) from the listing page I click to enter a new participant as in #1
above, but when the form appears, the form is filled with the last
record I entered or viewed. If I save that record, it creates a new
record with a new ID, but the current data.

Please note that I'm not using "generic messages". I have found other
entries on this but they were using MG's generic messages.

Looking at other articles about preservestate, if specified "false",
the data in the view state is supposed to be delete. At this point I
cannot tell if this is a MG problem or Reactor problem.

Anyone have any ideas?

Thanks in advance

Tom McNeer

unread,
Feb 13, 2008, 9:00:01 AM2/13/08
to model...@googlegroups.com
Could your browser be auto-filling the form?


--
Thanks,

Tom

Tom McNeer
MediumCool
http://www.mediumcool.com
1735 Johnson Road NE
Atlanta, GA 30306
404.589.0560

byron

unread,
Feb 13, 2008, 2:48:14 PM2/13/08
to model-glue
I'll check, but I don't think that's the case. If I load an existing
record, save it, the load another existing record, this does not
happen. Only when I load a new blank record after loading an existing
record does the last records info appear.

byron

On Feb 13, 9:00 am, "Tom McNeer" <tmcn...@gmail.com> wrote:
> Could your browser be auto-filling the form?
>
> --
> Thanks,
>
> Tom
>
> Tom McNeer
> MediumCoolhttp://www.mediumcool.com

Tom McNeer

unread,
Feb 13, 2008, 3:09:47 PM2/13/08
to model...@googlegroups.com
Byron,

On Feb 13, 2008 2:48 PM, byron <byron....@gmail.com> wrote:

I'll check, but I don't think that's the case.

Okay. Well, first I'll assume that your references to "redirect" and "preservestate" come within a <result> tag within your event-handler, correct? Are you sure that the "result" tag is being executed? That is, is it unnamed, or are you sure that the name of the result is being placed into the event?

Second, you've mentioned two different instances in which the behavior appears: after saving a new record, then attempting to enter another new record; and after saving an existing record, then attempting to enter a new record. In other words, any time you start a new record after entering or editing one. Is that correct?

If so, the next thing to look at would be your "loading" of a record. How are you doing that? Are you using Transfer or Reactor? If so, are you sure you're not retrieving a cached instance of the record object?

It would be helpful if you could post code: the relevant section of your M-G config, the method(s) called in the Controller, and any subsequent methods called in other objects.

byron

unread,
Feb 14, 2008, 12:36:59 AM2/14/08
to model-glue
Tom,

Thanks for the response. First, answers to your questions.

1.) Yes, the result tag is being executed. The data is saved and I'm
redirect to my participant listing.

<result name="commit" do="participant.list" redirect="true" append=""
preserveState="false" />

I also dumped the session._modelglue.forwardedStateContainer and the
struct is empty.

2.) Yes. Actually it is if I even view another record. I might save
that record or cancel to go back to the listing. Then, when a I call
up a blank form to enter a new record, the values from the last viewed
record (keyed on "ID") are shown in the form, even though I called the
form using 'ID=0'. The only way to stop it from happening is to do an
"init=true" to reinitialize the app.

3.) I'm using Reactor. Not sure if it is a cached instance. However,
if I'm loading a record that does not exist (ID=0 in my case) ,
shouldn't all variables be blank at that time?? This only happens
when loading a new record. I can load existing records and the data
in the form is correct.

Here is the relevant code:

From modelglue.xml:

<controller name="ParticipantController"
type="HopeWorks.controller.ParticipantController">
<message-listener message="getParticipants"
function="getParticipants"/>
<message-listener message="getParticipant"
function="getParticipant"/>
<message-listener message="saveParticipant"
function="saveParticipant"/>
<message-listener message="getControls"
function="getControls"/>
</controller>

<event-handler name="participant.list" access="public">
<broadcasts>
<message name="getCircleLeaders" />
<message name="getParticipants" />
</broadcasts>
<results>
<result do="view.template"/>
</results>
<views>
<include name="body"
template="dsp_ParticipantList.cfm" append="true">
<value name="xe.view" value="participant.view"
overwrite="true"/>
<value name="xe.delete" value="participant.delete"
overwrite="true"/>
<value name="xe.edit" value="participant.edit"
overwrite="true"/>
<value name="whichMenuIsCurrent" value="participant"/>
</include>
</views>
</event-handler>
<!-- edit participant information -->
<event-handler name="participant.edit" access="public">
<broadcasts>
<message name="getParticipant" />
<message name="getCircleLeaders" />
<message name="getCounties" />
<message name="getCC" />
</broadcasts>
<results>
<result do="view.template"/>
</results>
<views>
<include name="body" template="frm_Participant.cfm"
append="true">
<value name="xe.commit" value="participant.commit"
overwrite="true"/>
<value name="xe.list" value="participant.list"
overwrite="true"/>
<value name="whichMenuIsCurrent" value="participant"/>
</include>
</views>
</event-handler>
<!-- update participant data -->
<event-handler name="participant.Commit" access="public">
<broadcasts>
<message name="getParticipant" />
<message name="saveParticipant" />
</broadcasts>
<results>
<result name="commit" do="participant.list"
redirect="true" append="" preserveState="false" />
<result name="validationError"
do="participant.edit" redirect="false" append="ID" />
</results>
<views>
</views>
</event-handler>

particpantController.cfc

<cffunction name="getParticipant" access="public" returntype="void"
output="false" hint="">
<cfargument name="event" type="ModelGlue.Core.Event"
required="true" />

<cfset arguments.event.setValue('getParticipant',
getParticipantService().getParticipant(arguments.event.getValue('ID'))) /
>

</cffunction>

participantService.cfc

<cffunction name="getParticipant" access="public" output="false">
<cfargument name="ID" type="numeric" required="false" />

<cfreturn getParticipantDAO().load(ID=arguments.ID)>
</cffunction>

<cffunction name="saveParticipant" access="public" output="false">
<cfargument name="participantRecord"
type="reactor.base.abstractrecord" />

<cfreturn
getParticipantDAO().saveParticipant(participantRecord=arguments.participantRecord,argumentCollection=form) /
>

</cffunction>

From my frm_partiicpant:

<cfset listEvent = viewstate.getValue("myself") &
viewstate.getValue("xe.list") />
<cfset participantRecord = viewstate.getValue("getParticipant") />

<cfset ID = viewstate.getValue("ID")>

<cfset keyString = "&ID=#ID#" />
<cfset commitEvent = viewstate.getValue("myself") &
viewstate.getValue("xe.commit") & keyString />
<cfset validation = viewstate.getValue("participantValidation",
structNew()) />

<cfset PhaseID = viewstate.getValue("PhaseID") /> (set in controller
from a session variable

Let me know if I can provide other info.

Thanks

byron



On Feb 13, 3:09 pm, "Tom McNeer" <tmcn...@gmail.com> wrote:
> Byron,
>
> MediumCoolhttp://www.mediumcool.com

Tom McNeer

unread,
Feb 14, 2008, 9:23:04 AM2/14/08
to model...@googlegroups.com
Byron,

Thanks for being so complete. I haven't gone over every bit of the code, but at first blush I don't see a problem.

The first thing I'd wonder, however, is whether you're actually requesting a new (ID=0) record when you attempt to create a new participant record. How are you calling the event to create the new record? Meaning, do you have a "New Participant" button, hard-coded with an "ID=0", or something like that?

byron

unread,
Feb 14, 2008, 1:06:42 PM2/14/08
to model-glue
Tom,

Thanks for lookin at this.
I have a text link on the page.

<cfset editEvent = viewstate.getValue("myself") &
viewstate.getValue("xe.edit") />
<a href="<cfoutput>#editEvent#</cfoutput>&ID=0">Add Hope Circle
Participant</a>

Just for grins I did a form for it:

<form name="form1" action="<cfoutput>#editEvent#</cfoutput>"
method="post">
<input type="hidden" name="ID" value="0">
<input type="submit">
</form>

Still the same thing (which I would expect).

When I cfdump participantRecord.getID(), I do get a value of 0. So I
think it is loading a new record.

byron

Byron

On Feb 14, 9:23 am, "Tom McNeer" <tmcn...@gmail.com> wrote:
> Byron,
>

Tom McNeer

unread,
Feb 14, 2008, 1:37:34 PM2/14/08
to model...@googlegroups.com
When I cfdump participantRecord.getID(), I do get a value of 0.  So I
think it is loading a new record.

Okay. I assume you mean you're dumping this in the edit form view, where you say the form fields are being populated with the previous record's information.

If so, what do you see when you dump the participant record's memento? (I haven't used Reactor in a while, so I forget the exact method name, but it's something like getMemento() or getInstanceMemento().)

Are the form fields populated by things like participantRecord.getFirstName() and so on? If the Reactor record object being used inside the view is actually populated with an ID of 0 and other field values that come from a different record, it sounds as if a new record object is not being created. In looking at your Controller/Service code (although I can't see your DAO code), it does appear if you're just passing the ID along normally.

Does your load() method in the DAO simply always do a load(ID=whatever), regardless of whether the ID is 0 or not? Or is there logic that, for instance, creates the Reactor object, then calls load() only if the ID is not 0? This shouldn't make any difference, though, as long as you create the object first.

byron

unread,
Feb 14, 2008, 2:31:34 PM2/14/08
to model-glue
Tom,

>
> Okay. I assume you mean you're dumping this in the edit form view, where you
> say the form fields are being populated with the previous record's
> information.

Yes.
>
> If so, what do you see when you dump the participant record's memento? (I
> haven't used Reactor in a while, so I forget the exact method name, but it's
> something like getMemento() or getInstanceMemento().)
>

I can find any of these methods, so not sure what to do here.


> Are the form fields populated by things like participantRecord.getFirstName()
> and so on?

Yes.

> Does your load() method in the DAO simply always do a load(ID=whatever),
> regardless of whether the ID is 0 or not?

Yes.

Or is there logic that, for
> instance, creates the Reactor object, then calls load() *only* if the ID is
> not 0? This shouldn't make any difference, though, as long as you create the
> object first.

I'm always doing a load(ID=something)


It's got to be caching somewhere, just don't know why and how.

byron

>
> --
> Thanks,
>
> Tom
>
> Tom McNeer
> MediumCoolhttp://www.mediumcool.com

Tom McNeer

unread,
Feb 14, 2008, 7:12:59 PM2/14/08
to model...@googlegroups.com
Byron,

On Thu, Feb 14, 2008 at 2:31 PM, byron <byron....@gmail.com> wrote:
(I
> haven't used Reactor in a while, so I forget the exact method name, but it's
> something like getMemento() or getInstanceMemento().)
>

I can find any of these methods, so not sure what to do here.

Like I said, I haven't used Reactor in a while. You want to look at the object's transfer object, which will show you a struct of values, rather than all the getters and setters. The method is (I believe) either "getTO()" or "_getTO()". You could also just dump the getters individually. But since you're populating the form fields with getters, you're already seeing the values, so it doesn't matter.
 
> Does your load() method in the DAO simply always do a load(ID=whatever),
> regardless of whether the ID is 0 or not?


Yes.

 Or is there logic that, for
> instance, creates the Reactor object, then calls load() *only* if the ID is
> not 0? This shouldn't make any difference, though, as long as you create the
> object first.

I'm always doing a load(ID=something)

My point here was to experiment. If the ID being passed is 0, don't load a record. Just create one without loading.

I don't see why that should help; but then, I don't see why you're getting those bogus values, either.

It sounds as if you're setting an ID of 0 into an existing, populated object. Unfortunately, I don't have any other ideas right now. Good luck.

byron

unread,
Feb 15, 2008, 12:25:24 AM2/15/08
to model-glue
Tom,

Thanks again for your suggestions.

Doing a _getTo reveals that it must not be loading a blank record. It
is populated with the last record that is was loaded. Must be a
caching issues. It does not matter if I use:

load(ID=0) or load() or plain createRecord("tablename").

I'll keep looking around.

The crazy thing is that when I commit it does write a new record.

Byron

On Feb 14, 7:12 pm, "Tom McNeer" <tmcn...@gmail.com> wrote:
> Byron,
>
> MediumCoolhttp://www.mediumcool.com

Antony Sideropoulos

unread,
Feb 15, 2008, 4:46:01 AM2/15/08
to model...@googlegroups.com
Hi Byron
 
How is your database set up? is the ID an auto-incrementing primary key? is there actually a record with id = 0 in the database?

byron

unread,
Feb 15, 2008, 9:00:09 AM2/15/08
to model-glue
Antony,

MSSQL 2000. ID is the primary key and is set to auto-increment.
There is not a record with ID=0.

Byron

On Feb 15, 4:46 am, "Antony Sideropoulos"
<antonysideropou...@gmail.com> wrote:
> Hi Byron
>
> How is your database set up? is the ID an auto-incrementing primary key? is
> there actually a record with id = 0 in the database?
>

byron

unread,
Feb 15, 2008, 9:09:56 AM2/15/08
to model-glue
Tom,

For kicks, I changed my participant.edit event to a 'generic read'.

<message name="ModelGlue.genericRead">
<argument name="recordName" value="getParticipant" />
<argument name="criteria" value="ID" />
<argument name="object" value="tblParticipant" />
</message>

A blank record loads correctly when ID=0. So there must be something
weird in my participantController.cfc or participantService.cfc

One thing I did not include eariler was my coldspring.xml.

<beans>
<!-- This is your Model-Glue configuration -->
<bean id="modelGlueConfiguration"
class="ModelGlue.unity.framework.ModelGlueConfiguration">
<!-- Be sure to change reload to false when you go to production!
-->
<property name="reload"><value>false</value></property>
<!-- Rescaffold is overridden by reload - if reload is false,
rescaffold's setting doesn't matter -->
<property name="rescaffold"><value>false</value></property>
<!-- Be sure to change debug to false when you go to production! --
>
<property name="debug"><value>true</value></property>
<property name="defaultEvent"><value>hw.home</value></property>
<property name="reloadPassword"><value>true</value></property>
<property name="viewMappings"><value>/HopeWorks/views</value></
property>
<property name="generatedViewMapping"><value>/HopeWorks/views/
generated</value></property>
<property name="configurationPath"><value>config/ModelGlue.xml</
value></property>
<property name="scaffoldPath"><value>config/scaffolds/
Scaffolds.xml</value></property>
<property name="statePrecedence"><value>form</value></property>
<property name="reloadKey"><value>init</value></property>
<property name="eventValue"><value>event</value></property>
<property name="defaultTemplate"><value>index.cfm</value></
property>
<property name="defaultExceptionHandler"><value>exception</value></
property>
<property name="defaultCacheTimeout"><value>0</value></property>
<property
name="defaultScaffolds"><value>list,edit,view,commit,delete</value></
property>
</bean>

<!-- Setup Reactor -->
<bean id="reactorFactory" class="reactor.ReactorFactory">
<constructor-arg name="configuration">
<ref bean="reactorConfiguration" />
</constructor-arg>
</bean>

<!-- Setup participant-related components -->
<bean id="participantService"
class="HopeWorks.model.participantService">
<property name="reactorFactory">
<ref bean="reactorFactory" />
</property>
<property name="participantGateway">
<ref bean="participantGateway" />
</property>
<property name="participantDAO">
<ref bean="participantDAO" />
</property>
<property name="UDF">
<ref bean="UDF" />
</property>
</bean>

<bean id="participantGateway" factory-bean="reactorFactory"
factory-method="createGateway">
<constructor-arg name="objectAlias">
<value>tblParticipant</value>
</constructor-arg>
</bean>

<bean id="participantDAO" factory-bean="reactorFactory"
factory-method="createRecord">
<constructor-arg name="objectAlias">
<value>tblParticipant</value>
</constructor-arg>
</bean>

<alias alias="ormAdapter" name="ormAdapter.Reactor" />
<alias alias="ormService" name="ormService.Reactor" />
<bean id="reactorConfiguration" class="reactor.config.config">
<constructor-arg name="pathToConfigXml"><value>/HopeWorks/config/
reactor/Reactor.xml</value></constructor-arg>
<property name="project"><value>HopeWorks</value></property>
<property name="dsn"><value>HopeWorks</value></property>
<property name="type"><value>mssql</value></property>
<property name="mapping"><value>/HopeWorks/model/data/reactor</
value></property>
<property name="mode"><value>production</value></property>
</bean>


On Feb 15, 4:46 am, "Antony Sideropoulos"
<antonysideropou...@gmail.com> wrote:
> Hi Byron
>
> How is your database set up? is the ID an auto-incrementing primary key? is
> there actually a record with id = 0 in the database?
>

Tom McNeer

unread,
Feb 15, 2008, 9:34:56 AM2/15/08
to model...@googlegroups.com
Byron,

For kicks, I changed my participant.edit event to a 'generic read'.

A blank record loads correctly when ID=0.  So there must be something
weird in my participantController.cfc or participantService.cfc

I guess so; although I sure can't see anything obvious. Your controller and service are basically just passing the ID along to the DAO.

But from what you say, when you request an ID=0 record, you're getting the most recently loaded "real" record, with simply the ID field set to 0.

So somewhere, somehow, the object from the previous event is being passed along, and the ID is being changed to 0.

I don't have any idea how this is happening, unfortunately. I think you'll just have to spin up some test events/pages that break the sequence down: after you save the first record, you're redirected back to the "list" page. Dump the event scope there and see if a participant exists. And so on.

Sorry I don't have any better ideas. There's nothing I can see in your code offhand that would cause this. And Reactor doesn't have the sort of caching mechanism in it that Transfer does; at least, I don't think it does.
 

wkolcz

unread,
Feb 15, 2008, 11:24:21 AM2/15/08
to model...@googlegroups.com
Also, along those lines. Anyone know some fancy Reactor speak to get Unique records?

    <cffunction name="getAllFaculty" access="public" returntype="query" output="false" hint="I return the Faculty Profiles from the database">
    <cfscript>
                Faculty = application.reactor.createGateway("adm_EmployeeBios");
                query = Faculty.CreateQuery();
                query.returnObjectFields("adm_EmployeeBios","rank");
                where = query.getWhere();
                where.IsNotEqual("adm_EmployeeBios","Rank","3");
                order = query.getOrder();
                order.setAsc("adm_EmployeeBios","lastname");
                qryFaculy = Faculty.getByQuery(query);
            </cfscript>       
            <cfreturn qryFaculy>
    </cffunction>


Antony Sideropoulos

unread,
Feb 17, 2008, 11:08:43 PM2/17/08
to model...@googlegroups.com
Hi
 
Just noticed this in your code snippet:
 
<cfset PhaseID = viewstate.getValue("PhaseID") /> (set in controller
from a session variable
Any problems with the code that maintains this session variable?
 
Antony

byron

unread,
Feb 18, 2008, 12:26:57 AM2/18/08
to model-glue
Not that I can see. Is there anything in particular I should be
looking for?

Byron

On Feb 17, 11:08 pm, "Antony Sideropoulos"
<antonysideropou...@gmail.com> wrote:
> Hi
>
> Just noticed this in your code snippet:
>
> <cfset PhaseID = viewstate.getValue("PhaseID") /> (set in controller
> from a session variable
> Any problems with the code that maintains this session variable?
>
> Antony
>

Roy Martin

unread,
Feb 18, 2008, 4:30:51 AM2/18/08
to model...@googlegroups.com
Perhaps I'm missing something, but it appears you also have a custom commit what does this function do?

<cfreturn
getParticipantDAO().savePartic
ipant(participantRecord=arguments.participantRecord,argumentCollection=form) /
>


cfCharlie

unread,
Feb 18, 2008, 12:51:26 PM2/18/08
to model-glue
> 2) upon committing, I redirect to the list of particpants
> (name="commit" redirect="true" preservestate="false")

> 3) from the listing page I click to enter a new participant as in #1
> above, but when the form appears, the form is filled with the last
> record I entered or viewed. If I save that record, it creates a new
> record with a new ID, but the current data.

><cfset PhaseID = viewstate.getValue("PhaseID") /> (set in controller
>from a session variable


Try adding the PhaseID value held in session to the debug stack using
Trace on both of these events and make sure it has the value you
expect.

Jared Rypka-Hauer

unread,
Feb 18, 2008, 2:34:12 PM2/18/08
to model...@googlegroups.com
Note that I haven't read this thread in full yet... so if someone's
already said this, well, sorry for the repeat.

I would suggest that you do this in your form:

...page here...
<cfdump var="#ViewState.getAllValues()#" />
</body>
</html>

This will show you what's in the ViewState, and if you want to see
what's in your participant, you could do several things:

<cfset participant = ViewState.getValue("participant")>

<cfloop collection="#participant#" item="i">

<cfif left(3,i) IS "get">

<cfinvoke component="#participant#"
method="#i#"
returnvariable="retVar" />

<cfdump var="#retVar#" />

</cfif>

</cfloop>

This should help you compare the contents of your ViewState with the
values in your form...

J

On Feb 12, 2008, at 5:47 PM, byron wrote:

>
> I have an app running MG 2.0 (2.0.304), Coldspring, and Reactor

> (428). I'm running into the following problem. ...

byron

unread,
Feb 18, 2008, 11:55:54 PM2/18/08
to model-glue
Hi all. I have resolved the issue. It seems I was using the
participantDAO as a singleton. I rewrote my code and all is well.
Thanks to Brian Kotek for spotting that.

Thanks to all who have responded.

Byron

James Allen

unread,
Feb 19, 2008, 5:19:53 AM2/19/08
to model...@googlegroups.com
Phewwwwwww.. :)

Glad you got that sorted Byron. I was beginning to think this one would go
on forever.. ;)

The joys of Model-Glue..

Reply all
Reply to author
Forward
0 new messages